Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于重载部分的描述有些疑惑 #2

Open
peanut996 opened this issue Nov 15, 2020 · 1 comment
Open

关于重载部分的描述有些疑惑 #2

peanut996 opened this issue Nov 15, 2020 · 1 comment

Comments

@peanut996
Copy link

重载和重写的区别
此处提及

重载

发生在同一个类中,方法名必须相同,参数类型不同、个数不同、顺序不同,方法返回值和访问修饰符可以不同。

但是返回值和访问限制符号不同好像会报错。

public class HelloWorld {
    public void testFoo(){

    }
    public String testFoo() {
        return "";
    }

}

报错:Duplicate method testFoo() in type HelloWorld

@Gabriel-18
Copy link

返回值不同不能叫重载

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants