2016-06-29
1 polymorphic
Polymorphism, which is actually a variety of states of an object
In our example,
Tiger can be seen as tiger, or as animal
Animal t=new Tiger ();
Tiger T1=new Tiger ();
Cat can be seen as a cat, or as a animal
Dog can be seen as a dog, or as a animal.
Package com.java1995; /** @author*/Publicclass Animal {public void showMe () { System.out.println ("I am an animal");} }
package com.java1995; /** @author Administrator * */ public class Cat extends animal{ // public void ShowMe () { // System.out.println ("I Am a Cat"); //
package com.java1995; /** sub-class: Puppy * @author Administrator * */ public class Dog extends animal{ public void ShowMe () { System.out.println ( I am Puppy "
Package com.java1995; /** @author*/Publicclassextends animal{ publicvoid showMe () { System.out.println ("I am a Tiger");} }
Packagecom.java1995;/*** Test class *@authorAdministrator **/ Public classTest { Public Static voidMain (string[] args) {//Animal a=new Animal ();//A.showme (); //Animal t=new Tiger ();//t.showme ();// //Animal c=new Cat ();//c.showme (); /*** polymorphic, multiple states of an object*/Animal T=NewTiger (); Animal C=NewCat (); Animal D=NewDog (); ShowMe (d); } Public Static voidshowMe (Animal a) {a.showme (); }}
Resources
[1] Java Easy Start Classic tutorial "full version"
Java Section 35th polymorphism of three major features