Question 196
Given:
11. interface DeclareStuff{
12. public static final int EASY = 3;
13. void doStuff(int t); } //这儿,doStuff的权限是default
14. public class TestDeclare implements DeclareStuff {
15. public static void main(String [] args) {
16. int x = 5;
17. new TestDeclare().doStuff(++x);
18. }
19. void doStuff(int s) { //eclipse提示:Cannot reduce the visibility of the inherited method from DeclareStuff
//为什么啊?同样是default啊.
20. s += EASY + ++s;
21. System.out.println("s " + s)
22. }
23. }
Given:
11. interface DeclareStuff{
12. public static final int EASY = 3;
13. void doStuff(int t); } //这儿,doStuff的权限是default
14. public class TestDeclare implements DeclareStuff {
15. public static void main(String [] args) {
16. int x = 5;
17. new TestDeclare().doStuff(++x);
18. }
19. void doStuff(int s) { //eclipse提示:Cannot reduce the visibility of the inherited method from DeclareStuff
//为什么啊?同样是default啊.
20. s += EASY + ++s;
21. System.out.println("s " + s)
22. }
23. }
而不是楼主会所的 protected 出错很正常
而重写后的doStuff方法修饰符为default的,重写修饰变窄-----Complications fails