Method Overload ):
1. In the same class
2. Same method name
3. the number or type of parameters are different.
4. It is irrelevant to the return type of the method.
5. It is irrelevant to the modifier of the method.
Override ):
Method override must be a subclass that inherits the parent class to override the method of the parent class.
1. The method to be rewritten must have the same method name as the method to be rewritten.
2. The override method and the override method must have the same parameter list.
3. the return value type of the override method must be the same as the return value type of the method to be overwritten.
4. The access permission of the method to be rewritten cannot be reduced for the method to be rewritten.
Note that the override method must be the method of the parent class that can be accessed in the subclass.
Differences between method overloading and method Rewriting:
1. the overload is a method of the same name in the same class. The method name must be the same and the parameter list must be different, regardless of the type of the returned value.
2. Rewriting involves a method with the same name between the subclass and the parent class. The method name must be the same, the parameter list must be the same, and the return value type must be the same.
Method overload example:
Work (x, work () {0 work () {} View Code
If the test result is displayed, use this key plus. overload method directly.
Example of method Rewriting:
Child "nihao" View Code