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. } 

解决方案 »

  1.   

    实现接口后接口中的方法应该声明是public的吧
      

  2.   

    接口中的方法默认是public的,而类中的方法默认是friendly的,自然变小了,这是不允许的
      

  3.   

    Illegal modifier for the interface method DeclareStuff.doStuff(); only public & abstract are permitted你把接口中的doStuff前面加上个protected 试试不就知道啦。 提示原因就是上面的。 可以看出, 默认的是public, 所以你在实现类中要写上public修饰符 
      

  4.   

    接口访问修饰字 默认是public的 
    而不是楼主会所的 protected  出错很正常
      

  5.   

    接口中的变量和方法都是public,static,final的
    而重写后的doStuff方法修饰符为default的,重写修饰变窄-----Complications fails