Skip to content

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

Description

@puzige

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

重载

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

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

public class HelloWorld {
    public void testFoo(){

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

}

报错:Duplicate method testFoo() in type HelloWorld

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions