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 [2015/02/15 17:40] – 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 | + | Animal |
| - | Animal | + | Animal |
| - | + | ||
| - | Animal.testClassMethod(); | + | Animal.testClassMethod(); |
| - | Cat.testClassMethod(); | + | Cat.testClassMethod(); |
| - | | + | |
| - | myAnimal.testClassMethod(); | + | myAnimalCat.testClassMethod(); |
| - | | + | |
| - | myCat.testClassMethod(); | + | myCat.testClassMethod(); |
| - | | + | |
| - | + | ||
| - | myCat.testInstanceMethod(); | + | |
| - | myAnimal.testInstanceMethod(); | + | myAnimal.testInstanceMethod(); |
| - | | + | myCat.testInstanceMethod(); |
| - | } | + | |
| } | } | ||
| </ | </ | ||
| Line 60: | Line 60: | ||
| The static method in Cat | The static method in Cat | ||
| - | The instance method in Cat | ||
| The instance method in Cat | The instance method in Cat | ||
| The instance method in Animal | The instance method in Animal | ||
| + | The instance method in Cat | ||
| </ | </ | ||
| - | Παρατηρούμε ότι ο τύπος των δεδομένων από τον οποίο καλούμε μία στατική μέθοδο είναι καθοριστικός για το ποια μέθοδος θα κλήθεί τελικά. Για παράδειγμα, | + | Παρατηρούμε ότι ο τύπος των δεδομένων από τον οποίο καλούμε μία στατική μέθοδο είναι καθοριστικός για το ποια μέθοδος θα κλήθεί τελικά. Για παράδειγμα, |
| Οι 3 τελευταίες γραμμές του προγράμματος αναφέρονται σε δυναμικό πολυμορφισμό για να δείξουν την αντίθεση των αποτελεσμάτων στην κλήση στατικών και μη στατικών μεθόδων. | Οι 3 τελευταίες γραμμές του προγράμματος αναφέρονται σε δυναμικό πολυμορφισμό για να δείξουν την αντίθεση των αποτελεσμάτων στην κλήση στατικών και μη στατικών μεθόδων. | ||
| - | |Προηγούμενο: | + | |Προηγούμενο: |
java/hiding_static_methods.1424022041.txt.gz · Last modified: 2015/02/15 17:40 (external edit)
