Home  >  Article  >  Java  >  The difference between overloading and rewriting in java

The difference between overloading and rewriting in java

尚
Original
2019-12-02 16:05:083304browse

The difference between overloading and rewriting in java

The difference between java overloading and rewriting: (Recommended: java video tutorial)

1. Definition difference:

① Overloading means that different functions use the same function name, but the number or type of parameters of the function is different. Different functions are distinguished according to the parameters of the function when calling.

②Overwriting (also called rewriting) refers to reimplementing the virtual function (note that it is a virtual function) in the base class in the derived class. That is, the function name and parameters are the same, but the implementation of the function is different.

2. The difference in class relationships

Overlay is the relationship between subclasses and parent classes, which is a vertical relationship; overloading is the relationship between methods in the same class, which is a horizontal relationship. .

3. Differences in generating methods

Override can only be generated by one method or a pair of methods; overloading is the relationship between multiple methods.

4. Difference in parameter list requirements

Overwriting requires the same parameter list; overloading requires different parameter lists.

5. Differences in calling methods

In the coverage relationship, the calling method body is determined based on the type of the object; while the overloading relationship is selected based on the actual parameter list and formal parameter list when calling. method body.

For more java knowledge, please pay attention to the java basic tutorial column.

The above is the detailed content of The difference between overloading and rewriting in java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn