Abstract classes: Classes with abstract methods that need to be decorated with the abstractions keyword
Relationship Diagram
The code below
Package com.ray.testobject;/** * Abstract class * * @author Ray * @since 2015-05-02 * @version 1.0 * */public abstract class person {public abstract void getdescription ();}
Package com.ray.testobject;/** * Implementation class * * @author Ray * @since 2015-05-02 * @version 1.0 * */public class Man extends P Erson {@Overridepublic void GetDescription () {System.out.println ("I Am a Man");}}
Package com.ray.testobject;/** * continues to abstract a class * * @author Ray * @since 2015-05-02 * @version 1.0 * */public abstract class Woman extends person {public abstract void getdescription ();}
Package com.ray.testobject;/** * Implementation class * * @author Ray * @since 2015-05-02 * @version 1.0 * */public class Beatifulwoman Extends Woman {@Overridepublic void GetDescription () {System.out.println ("I am a beatiful Woman");}}
Package com.ray.testobject;/** * Testing class * * @author Ray * @since 2015-05-02 * @version 1.0 */public Class Test {public St atic void Main (string[] args) {person mans = new Man (); Person Beatifulwoman = new Beatifulwoman (); person[] persons = new PERSON[2];p ersons[0] = man;persons[1] = beatifulwoman;for (int i = 0; i < persons.length; i++) { Persons[i].getdescription ();}}}
Output:
I am a man
I am a beatiful woman
In fact, here is the main explanation is the test inside for the loop inside, each person's class, the implementation of the sub-class
The subclass then implements the abstract method of the parent class, requiring only the parent class to refer to the subclass object, which can be called by invoking the same method and then outputting different things
In particular, it is necessary to note that abstract classes are not instantiated.
Getting Started with Java Basics-parent class referencing subclass object (2)-abstract class