Definition: The various forms of existence of a certain class of things.
Example: Animals in cats, dogs.
Cats This object corresponds to the type of cat type
Cat x = new Cat ();
The cat is also a kind of animal, can also call the cat animal
Animal y = new Cat ();
Animals are the type of parent extracted from the specific things of cats and dogs.
Result: The parent type reference points to the child class object
The code reflects:
Abstract class Animal{abstract void Eat ();} Class Cat extends Animal{public void Eat () {System.out.println ("eat Fish");} public void Catchmouse () {System.out.println ("catch Mouse");}} Class Dog extends Animal{public void Eat () {System.out.println ("eat Bones");} public void Kanjia () {System.out.println ("housekeeping");}} -----------------------------------------class Duotaidemo {public static void main (string[] args) {function (new Cat ( )); Eat fish function (new Dog);//eat bone}public static void function (Animal a)//animal a = new Cat (); {a.eat ();}}
Polymorphic (i)