Difference between method overloading and overriding

Overiding: The premise is that there must be an inheritance relationship. When a method of the parent class cannot meet the needs of the subclass, the method must be rewritten in the subclass.

Requirements for method overriding:

1. The method name and formal parameters must be the same

2. The permission modifier of the subclass must be greater than or equal to the permission modifier of the parent class

3. The return type of the subclass must be less than or equal to the return type of the superclass

4. The exception type thrown by the subclass must be less than or equal to the exception type thrown by the parent class

Overloading: Method overloading is a way for classes to handle different types of data in a uniform way. In the same class, there are two or more methods with the same name, this is called method overloading

Requirements for method overloading:

1. The method name must be the same

2. The parameter list must be different

3. Regardless of the return type

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324746526&siteId=291194637