When a Java instantiation calls an abstract method or a method within a class, if the subclass has a rewrite method, the subclass override method is actually running.
Packageauto.test;//Abstract Parent Class Public Abstract classFather { PublicFather () {//TODO auto-generated Constructor stubOupput ();//Called when instantiated, subclasses have, call child class method, subclass no, Call parent class method } //Parent class abstract method, let subclasses override Public voidOupput () {System.out.println ("From Father class"); };}//sub-Class AclassChildaextendsfather{//overriding the parent class method@Override Public voidOupput () {System.out.println ("From Childa class"); }}//sub-Class BclassChildbextendsFather {//overriding the parent class method@Override Public voidOupput () {System.out.println ("From Childb class"); }}classChildcextendsFather {//no overriding parent class methodExecute the test class Public classTestclaass { PublicTestclaass () {//TODO auto-generated Constructor stub } Public Static voidMain (String arg[]) {Father a=NewChilda (); Father b=Newchildb (); Father C=NewCHILDC (); }}
Operation Result:
From Childa class
From Childb class
From Father class
Java instantiation is a subclass override method called