Java basic study notes _ the difference between method overloading and method rewriting

 

Overload

Override

Method name the same the same
parameter list Different (number or data type of corresponding position) the same
Return value type Irrelevant the same
Modifier Irrelevant Access rights are not less than the method being overridden
Define location In the same class Child parent class

 

 

 

 

 

 

 

Method overloading : a means for classes to handle different types of data in a unified way. 

Method rewriting : reflects the polymorphism between the parent class and the child class, and the child class redefines the function of the parent class. If a method defined in a subclass has the same method name, parameter list, and return value type as its parent class, we say that the method is overridden (Override).

Rough understanding: Method rewriting means everything is the same, and the method body may be different. Method overloading means that the method name is the same, the parameter list is different, and it has nothing to do with the return value type and modifiers.

Guess you like

Origin blog.csdn.net/qq_43191910/article/details/114757766
Recommended