Polymorphism


Are you having trouble understanding polymorphsim? Here are some programs that might help.

These files are from the class example, Lions and Tigers and Bears, oh my!

Animal.java

Lion.java

Tiger.java

Bear.java

ZooKeeper.java

ZooApplication.java

Sample print out:

Yawn -- G r o w l - Laydown -- Close Eyes
Pace -- Climb Tree -- Close Eyes
Walk into cave -- curl up -- Close eyes
Yawn -- G r o w l - Laydown -- Close Eyes

Having trouble with the polymorphism assignment? Then you might want to see these files for a hint at one way to do some of the assignment.

Shape.java

Circle.java

Square.java

ShapeFrame.java

What about polymorphism and static methods? Look at these files. The tester file calls an over written static method at various levels and from instance variables. The results may surprise you, they did me.

SuperSuperClass.java

SuperClass.java

SubClass.java

StaticMethodTester.java

Sample print out:

Print identify self from instance
This is the Supersuper Class.
This is the Super Class
This is the subclass.
Print identify self from Class name
This is the Supersuper Class.
This is the Super Class
This is the subclass.
Print from subclass instance supersuper method.
This is the subclass.
Print from polymorph variable
This is the Supersuper Class.

Return to the Java Help Page