Object-oriented three features: encapsulation, inheritance, polymorphism
This section is the embodiment of object-oriented polymorphism
1. Upward transformation of objects
The upward transformation----assigns the object of the subclass to a reference to the parent class;
Student s = new Student ();
Person p = s;
Or it can be written
Person p = new Student ();
What members (variables and functions) can be called by a reference, depending on the data type of the application
Which method a reference invokes depends on the object to which the reference refers (the member variables and methods that are called subclasses)
2. Object-Down transformation
Transition down----Assign the object of the parent class to a reference to the subclass:
Student S1 = new Student ();
Person p = S1;
Student s2 = (Student) p;
The directly generated parent class cannot be transformed into a subclass object;
Java Fundamentals Section----4. Transformation of objects