Final, polymorphic
1. Final
Final: Constant, cannot be modified. Classes can be decorated (cannot be inherited), methods (cannot be overridden), variables (can only be assigned once).
Caveats: Final decorated base type, the value of the base type cannot be changed.
The final decorated reference type, the address of the reference type cannot be changed, and the value in the object heap can be changed.
Final static constants are best assigned when declared, and non-static constants are best assigned before the end of the constructor.
2. polymorphic
Polymorphism: A thing that states in different timetables, such as: Cat is Cat "cat c=new Cat ();", Cat is Animal "Animal c=new Cat ();".
The precondition of polymorphism: there is inheritance, there is a method of rewriting, there is a parent class reference subclass.
The advantages of polymorphism: It improves the maintainability and extensibility of the code.
The disadvantage of polymorphism: The parent class cannot access the features that are unique to subclasses (can be accessed through strong transfers, such as: Father f=new Son (); Son s= (son) F; ) 。
Note: Subclasses can access the contents of the parent class, and the parent class cannot access the contents of the child class.
When the parent class is the new subclass, access the constructor of the parent class.
When the parent class is new, the static method compiles and runs the contents of the parent class (because the static method is only related to the class).
When the parent class is new, the member variable, the member method compiles the contents of the parent class, the member variable runs the contents of the parent class, and the member method runs the contents of the subclass.
Older Dick Silk Self-study note--java 0 basics to rookie--018