An object of a subclass is transformed upward to the object of a parent class, and the properties and methods that are called in the parent class are the child class objects that are pointed to.
That is, the method that points to the replication override in the subclass.
The upward transformation is not likely to fail.
//What members (variables and functions) can be called by a reference, depending on the type of the reference//which method is called by a reference, depending on the object to which the reference is directedclasstest{ Public Static voidMain (String args []) {//Student s = new Student (); //Person p = s;Person p =NewStudent ();//Upward TransformationStudent s = (Student) p;//downward transformation must first be transformed to a downward transformation, or the wrong transformationP.name="Zhangsan"; P.age= -; //The wrong p.address = "Beijing";p.introduce (); }}
class person{ String name; int Age ; void introduce () { System. out. println ( "+ name +"" + Age" ); } }
class Student extends person{ String address; void Study () { System. out. println (" I'm learning "); } void introduce () { super.introduce (); System. out. println (" my home is in "+ address);} }
Transformation of the "seven" objects