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

1.4.3.2. 重写 返回值类型 #892

Closed
lichengjie19 opened this issue Aug 11, 2020 · 3 comments
Closed

1.4.3.2. 重写 返回值类型 #892

lichengjie19 opened this issue Aug 11, 2020 · 3 comments
Labels
enhancement New feature or request or suggestion perfect Improve knowledge points or descriptions

Comments

@lichengjie19
Copy link

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

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

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

sruby commented Aug 13, 2020

这里确实存在问题,《疯狂 Java 讲义》是正确的。

@Snailclimb
Copy link
Owner

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

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

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

赞赞赞!学到了。已经修改。
image

@Snailclimb Snailclimb added enhancement New feature or request or suggestion perfect Improve knowledge points or descriptions labels Aug 14, 2020
@liuyaofang996
Copy link

小: 指的是子类

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request or suggestion perfect Improve knowledge points or descriptions
Projects
None yet
Development

No branches or pull requests

4 participants