Class A, and another class B inherits Class A. The following code is available:
A = new B (); This is called the parent class's reference A to the subclass object, new B ();
If your A is an interface, or an abstract class, then it is not possible to create an object, so that writing can also be used to refer to his subclass or to the object that implements the class. It's not obvious that this sentence is written here. In fact, it is mainly used in the parameters of the method, that is, polymorphism (one of the three characteristics of Java, can think how important), in order to let you understand deeply, I give an example.
If there is a class, this class needs to be implemented to eat all kinds of fruits, bananas, apples, pears and so on.
Do we have to write:
Public void Eat (Banana Banana) {//...}
Public void Eat (Apple apple) {//...}
Wait, wait. This is not a very troublesome ah, but if I write this method:
So as long as the inheritance of fruit or implement fruit interface, can be used as eat parameters, is not greatly simplified programming.
Object-oriented, you slowly realize it, fun.
The Java parent refers to the object meaning of the child class