Analysis of Java object transformation
This article describes the concept of Java object transformation with examples, which can be shared for your reference. The specific methods are as follows:
Precautions for object casting are as follows:
1. The reference type variable of a base class can "point" to the object of its subclass.
2. A reference to a base class cannot access the newly added members (properties and methods) of its subclass objects.
3. You can use the instanceof class name of the reference variable to determine whether the object "pointed to" by the reference variable belongs to this class or a subclass of this class.
4. Objects of subclasses can be used as objects of base classes, which are called upcasting, and vice versa.
The specific implementation code is as follows:
The operation results are shown in the figure below:
I hope this article is helpful to your Java programming