java:hiding_static_methods
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| java:hiding_static_methods [2016/02/15 09:10] – gthanos | java:hiding_static_methods [2017/03/03 14:03] (current) – gthanos | ||
|---|---|---|---|
| Line 5: | Line 5: | ||
| <code java Animal.java> | <code java Animal.java> | ||
| public class Animal { | public class Animal { | ||
| - | | + | |
| - | System.out.println(" | + | System.out.println(" |
| - | } | + | } |
| - | public void testInstanceMethod() { | + | public void testInstanceMethod() { |
| - | System.out.println(" | + | System.out.println(" |
| - | } | + | } |
| } | } | ||
| </ | </ | ||
| Line 16: | Line 16: | ||
| <code java Cat.java> | <code java Cat.java> | ||
| public class Cat extends Animal { | public class Cat extends Animal { | ||
| - | | + | |
| - | System.out.println(" | + | System.out.println(" |
| - | } | + | } |
| - | public void testInstanceMethod() { | + | public void testInstanceMethod() { |
| - | System.out.println(" | + | System.out.println(" |
| - | } | + | } |
| } | } | ||
| </ | </ | ||
| Line 27: | Line 27: | ||
| <code java TestCat.java> | <code java TestCat.java> | ||
| public class TestCat { | public class TestCat { | ||
| - | | + | |
| - | Cat myCat = new Cat(); | + | Cat myCat = new Cat(); |
| - | Animal myAnimalCat = myCat; | + | Animal myAnimalCat = myCat; |
| - | Animal myAnimal = new Animal(); | + | Animal myAnimal = new Animal(); |
| - | + | ||
| - | Animal.testClassMethod(); | + | Animal.testClassMethod(); |
| - | Cat.testClassMethod(); | + | Cat.testClassMethod(); |
| - | | + | |
| - | | + | |
| - | myAnimal.testClassMethod(); | + | myAnimal.testClassMethod(); |
| - | myCat.testClassMethod(); | + | myCat.testClassMethod(); |
| - | | + | |
| - | + | ||
| - | myAnimalCat.testInstanceMethod(); | + | myAnimalCat.testInstanceMethod(); |
| - | myAnimal.testInstanceMethod(); | + | myAnimal.testInstanceMethod(); |
| - | myCat.testInstanceMethod(); | + | myCat.testInstanceMethod(); |
| - | } | + | |
| } | } | ||
| </ | </ | ||
| Line 63: | Line 63: | ||
| The instance method in Animal | The instance method in Animal | ||
| The instance method in Cat | The instance method in Cat | ||
| - | |||
| </ | </ | ||
| Line 70: | Line 69: | ||
| Οι 3 τελευταίες γραμμές του προγράμματος αναφέρονται σε δυναμικό πολυμορφισμό για να δείξουν την αντίθεση των αποτελεσμάτων στην κλήση στατικών και μη στατικών μεθόδων. | Οι 3 τελευταίες γραμμές του προγράμματος αναφέρονται σε δυναμικό πολυμορφισμό για να δείξουν την αντίθεση των αποτελεσμάτων στην κλήση στατικών και μη στατικών μεθόδων. | ||
| - | |Προηγούμενο: | + | |Προηγούμενο: |
java/hiding_static_methods.1455527412.txt.gz · Last modified: 2016/02/15 09:10 by gthanos
