The most important thing is the understanding of polymorphism. Remember that when I first looked at the first example of polymorphism, I was particularly uncomfortable with the output. The C ++ polymorphism I learned has forgotten so far. polymorphism is hard to understand.
Write down the interesting things in the book first: Because Java is bound later, during compilation, the compiler's job is to ensure that the called method exists, check the type of the called parameters and returned values, but do not know the exactCode. InProgramThe Code address can be determined only when the Java virtual machine is running to execute the code!
To perform later binding, Java uses a small segment of special code. This Code uses the information stored in the object to calculate the address of the method body (what does this code look like? This is my only question ). Reference a man on the Net: The Virtual Machine obtains a specific object based on the runtime type information and calls the method of this object. It seems a bit reasonable. I haven't finished the type information chapter, but I still want to know the specific code. Do the online heroes have some good opinions? Polymorphism also needs to be learned and understood!
The second story about upward transformation and downward transformation seems to have lost my identity, but I have always understood the loss of data as an error in C ++. Therefore, I always have a question: what problems will happen if we perform a downward transformation after an upward transformation? Fortunately, the transformation is only for reference. If it is converted to a reference type, you can only operate on this type.
Class base {public void printhello () {system. Out. println ("Hello world! ") ;}} Class down extends base {public void printhello () {system. Out. println (" Down Hello world! ");} Public void printother () {system. Out. println (" Other all over the world is OK! ") ;}} Public class converseclass {public static void main (string [] ARGs) {down d = new down (); Base B = D; B. printhello (); // B. printother (); (down) B ). printother ();}}
The output results still involve polymorphism. Therefore, polymorphism and transformation still need to be understood.