Home > Java > javaTutorial > What is the difference between Overload and Override in java

What is the difference between Overload and Override in java

PHPz
Release: 2023-04-29 10:10:06
forward
1019 people have browsed it

The difference between Overload and Override

Overload means that there can be multiple methods with the same name in the same class, but the parameter lists of these methods are different, that is, the parameters The parameters or parameter types are different. Of course, the return value can be different during overloading, but if the parameter list is completely consistent, overloading cannot be achieved through inconsistent return types. This is not allowed.

Override means that the method in the subclass can have the same name and parameters as the method in the parent class. When this method is called through an object created by the subclass, the method defined in the subclass will be called, that is, It is the method in the subclass that overrides the method in the parent class. When a subclass overrides a parent class method, it can only throw fewer or smaller exceptions than the parent class. The return of the overridden method must be consistent with the return of the overridden method.

What are the basic data types of java

The basic data types of Java are divided into: 1. Integer type, used to represent the data type of integer. 2. Floating point type, a data type used to represent decimals. 3. Character type. The keyword of character type is "char". 4. Boolean type is the basic data type that represents logical values.

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

Related labels:
source:yisu.com
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template