Skip to content

1.4.3.2. 重写 返回值类型 #892

Description

@lichengjie19

在 暖心的 Guide 哥 总结的图表中,重写方法的返回类型一定不能修改 这个不对吧

以下内容摘录自《疯狂 Java 讲义》
方法的重写要遵循“两同两小一大”:

  • “两同”即方法名相同、形参列表相同;
  • “两小”指的是子类方法返回值类型应比父类方法返回值类型更小或相等,子类方法声明抛出的异常类应比父类方法声明抛出的异常类更小或相等;
  • “一大”指的是子类方法的访问权限应比父类方法的访问权限更大或相等。

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

    enhancementNew feature or request or suggestionperfectImprove knowledge points or descriptions

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions