Polymorphism--concept
a multi-state refers to a reference (type) A variety of states in different situations. It can also be understood that polymorphism refers to a method that is implemented in a different subclass by pointing to a pointer to the parent class.
There are two ways to implement polymorphism:1, inheritance, 2, interface
Polymorphism--Precautions:
1. Java allows a reference variable of the parent class to refer to an instance of its subclass (object)
Animal an=new Cat ();//This conversion is done automatically
inheritance is the basis for the realization of polymorphism. Literally, polymorphism is a type (all car type) that shows a variety of states (BMW's name is BMW, the price is 300000; the name of the Chery car is cheryqq, the price is 2000). Associating a method call with the principal (that is, an object or a class) to which the method belongs is called binding, which is both pre-binding and late-bound. Here's how they're defined:
1. Early binding: Binding before the program runs, implemented by the compiler and the linker, also called static binding. For example, the static method and the final method, note that this also includes the private method, because it is implicitly final.
2. Late binding: Binding according to the type of the object at run time, implemented by the method invocation mechanism, is also called dynamic binding, or run-time binding. All methods except pre-binding are late-bound.
Polymorphism is achieved on the mechanism of late binding. The benefit of polymorphism is that it eliminates the coupling between classes and makes the program easier to extend.
Final concept
Final Chinese meaning: The last, the final.
Final can modify variables or methods.
In some cases, the programmer may have the following requirements:
1. When you do not want a method of the parent class to overwrite (override) The quilt class, you can use the final keyword to decorate it.
2. When you do not want the value of a variable of a class to be modified, you can use the final modifier. If a variable is final, the initial value must be assigned, or a compilation error occurs.
3, when you do not want the class to be inherited, you can use the final decoration.
About the characteristics of Java polymorphism