java overloaded and rewrite the difference between (first need to look at polymorphic)

Polymorphic: Popular, in general, the same form, different performance.

 

Do not look too long Series:

The so-called polymorphism, refers to a specific type of reference variables defined in the program pointed to by the reference variables and the method call issued when programming is not determined, but is determined only during the program run, i.e. it is going to be a variable reference point which instance of an object class, this reference variable method calls made in the end is which class method implemented, in order to be determined by the program is running. Since determine the specific class only when the program is running, so, without modifying the source code, you can make reference variable is bound to achieve a variety of different classes, resulting in specific reference to the method invocation will change, that does not modify the program code can change specific code to run when bound, so that the program can select multiple operating states, this is polymorphism.

 

Overload ① Method: the same method name, according to the type and number of parameters passed in different ways different execution thereof; (polymorphism may be understood as a matter of opinion)

② override method: the same method, based on different sub-classes, different functions. (Must be polymorphic)

 

Overloaded: the name of the same method, but the type or number of different parameters, focusing can be understood as a class polymorphism. ,

Rewriting: subclass inherits the parent class, subclass to override inherited methods (covered), the number and type of parameters are the same, but different specific methods to achieve. Achieved through dynamic binding.

   Method subclass covers a method of the parent class: the same method name, return the same type of class value, the same parameter list, modifiers may be different (less than the parent class is not a subclass of access). The new method covers the parent class method, if the parent class of the original method to use, can be used to call the super keyword.

 

And rewriting the dynamic type is determined, the operation time is determined, is the dynamic assignment, dynamically assigned by the virtual method table implementation, the virtual method table for each method in the presence of an actual entry address.

                                                                                                                                                                                                              

Guess you like

Origin www.cnblogs.com/xiaojinren/p/11614515.html