|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objecttips.polymorph.Pet
tips.polymorph.Dog
Demonstrating Polymorphism. myPet ISA Pet even though it references a DOG so myPet instanceof Dog will return true - a Pet ISA Dog in this casw. But calling myPet.scratch() will call the Dog's method.
Output
Creating a Pet
Creating a Dog
Pet Function
Dog is scratching
Dog is eating
A Dog ISA Dog ISA Dog
| Field Summary | |
(package private) int |
nAmount
|
| Constructor Summary | |
Dog()
Creates a new instance of Dog |
|
| Method Summary | |
Pet |
eat()
A bad function.... |
static void |
main(java.lang.String[] args)
Use the main method to show what's going on. |
void |
petFunction()
|
void |
scratch()
The dog is scratching - probably flees |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
int nAmount
| Constructor Detail |
public Dog()
| Method Detail |
public void scratch()
scratch in class Petpublic Pet eat()
eat in class Petpublic static void main(java.lang.String[] args)
public void petFunction()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||