Home> Java> javaTutorial> body text

Overloading in Java can achieve different return values

coldplay.xixi
Release: 2020-09-02 13:12:10
Original
4273 people have browsed it

Overloading in Java cannot achieve different return values. Method overloading has nothing to do with the return value type and modifiers. Overloading in Java occurs in this class, and the condition for overloading is in this class. There are multiple methods with the same name but different parameter lists, which have nothing to do with the return value.

Overloading in Java can achieve different return values

Overloading in Java cannot return different values

Method overloading is related to the return value type and Modifiers are irrelevant, Java overloading occurs in this class. The condition for overloading is that there are multiple methods with the same name in this class, but different parameter lists (maybe the number of parameters is different, the parameter type different), has nothing to do with the return value.

We can give an example, if we write two methods in the same class with the same name and the same parameter list, but the return value is different,

public Stringshow(int number) public int show(int number)
Copy after login

And we call this method When assigning a value to it, the Java virtual machine does not know whether you want to assign it to a String type method or an int type method, so overloading has nothing to do with the return value.

Related learning recommendations:java basics

The above is the detailed content of Overloading in Java can achieve different return values. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!