1. Definition
If Class B is a subclass of Class A or an indirect subclass, when you create object B with Class B and assign a reference to object B to class A, such as:
A a;
a = new B();
OR
A a;
B b = new B();
a = b;
It is said that Class A object A is the upper transformation object of subclass B object B.
2. Nature
The entity of the upper transformation A of object B is created with subclass B, but the upper transformation object loses some of the properties and functions of sub-class B. The above transformation objects have the following characteristics:
- On a transformed object cannot manipulate the newly added member variables of the subclass, you cannot use the new method of the subclass. That is to lose some properties and functionality for sub-class B, these properties and functions are new.
- On a transformed object you can manipulate member variables that are inherited or hidden by subclasses, or you can use a subclass-inherited or overridden method. That is, the upper transformation object can manipulate the original properties and functions of the parent class, regardless of whether the methods are overridden.
- When you invoke a method on a transformed object, you invoke a method that inherits and is overridden by the child class.
- You can then cast the object's upper transformation object to a subclass object, and the cast object has all the properties and functions of the subclass.
- Only occurs in the inheritance.
About the top transformation object in Java