tips.polymorph
Class Dog

java.lang.Object
  extended bytips.polymorph.Pet
      extended bytips.polymorph.Dog

public class Dog
extends Pet

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

nAmount

int nAmount
Constructor Detail

Dog

public Dog()
Creates a new instance of Dog

Method Detail

scratch

public void scratch()
The dog is scratching - probably flees

Overrides:
scratch in class Pet
Returns:
void

eat

public Pet eat()
A bad function....

Overrides:
eat in class Pet
Returns:
Pet a pointer to ourselves

main

public static void main(java.lang.String[] args)
Use the main method to show what's going on.


petFunction

public void petFunction()