What is the alias reference mechanism of Java? The alias reference mechanism of Java (originally Aliasing, alias, namely polymorphism in Java) means that multiple referenced variables can be located on the same physical object, the referenced variables can be of different types. in the following code, the S Class inherits the P class, And the pp and ss are the two array variable names of the P and S types respectively. [java] public class TestPolyMorphism {public static class P {public void print (String message) {System. out. println ("P -->" + message) ;}} public static class S extends P {public void print (String message) {System. out. println ("S -->" + message) ;}} public static void m Ain (String [] args) {S [] ss = new S [10]; P [] pp = ss; ss [0] = new S (); pp [0]. print ("hello ");//!! Runtime error. The parent class object cannot be assigned to the subclass array; // pp [1] = new P (); // java. lang. arrayStoreException} in the memory, both pp and ss point to the same memory address. (we can say that the pointer pp, pointer ss; or pp reference, ss reference .) figure 1 PP and ss point to the same physical address. during actual operation, the polymorphism feature determines whether to call a specific method of parent class or subclass based on the actual object type, instead of referencing the variable type. how does Java handle the alias reference mechanism? If the following code is copied to eclipse, there will be no compilation errors: [java] package think; public class TestPolyMorphism {public static class P {public void print (String message) {System. out. println ("P -->" + message) ;}} pub Lic static class S extends P {public void print (String message) {System. out. println ("S -->" + message);} public void paint (String message) {System. out. println ("S --> execute some painting operations -->" + message) ;}} public static void main (String [] args) {S [] arr = new S [10]; P [] pp = arr; arr [0] = new S (); pp [0]. print ("hello"); pp [1] = new P ();//!! Runtime error. The parent class object cannot be assigned to the subclass array; java. lang. arrayStoreException} but the following error is displayed at runtime: [plain] Exception in thread "main" java. lang. arrayStoreException: think. testPolyMorphism $ P at think. testPolyMorphism. main (TestPolyMorphism. java: 22) the reason is that the alias reference is processed during Java runtime. During the program running, the VM finds that the first element of the array pp is an SS-type object, not a PP-type object. Therefore, only the correct code can run properly: [java] S [] arr = new S [10]; P [] pp = arr; pp [1] = new S (); pp [1]. print ("hello"); no output error: [plain] view plaincopy view the CODE piece on the CODE to derive to my CODE piece S --> hello