interface DeclareStuff {
public static final int EASY = 3;
void doStuff(int t);
}class TestDeclare implements DeclareStuff {public static void main (String [] args)
{ int x =5;
   new TestDeclare().doStuff(++x);}
void doStuff (int s){
s+=EASY + ++s;
System.out.println("s"+s);}
}

解决方案 »

  1.   

    在TestDeclare类中的doStuff方法前加上public,interface中只允许public方法声明,
    无论其是否有public,方法声明都被认为是public的,所以在实现类中必须加上public,
    否则会认为方法的可见性被降低而造成编译错误。
      

  2.   

    interface DeclareStuff {
    public static final int EASY = 3; public void doStuff(int t);
    }class TestDeclare implements DeclareStuff { public static void main(String[] args) {
    int x = 5;
    new TestDeclare().doStuff(++x); } public void doStuff(int s) {
    s += EASY + ++s;
    System.out.println("s" + s);

    }
    }接口中的方法是public abstract型 所以在类实现接口的方法时要用public来修饰这样就没错误了
      

  3.   

    哦 好的哦 谢谢了哦 
    那我刚才编译下面这段interface DeclareStuff {
        public static final int EASY = 3;     void doStuff(int t);
    }
    这样为什么不报错。
      

  4.   

    这个当然不报错,所有在interface中声明的属性和方法都默认是public的,即时你不写,实际上对于变量,默认的是
    public static final,所以对于上面这个接口,这么写也是可以的,而且效果相同。
    interface DeclareStuff {
        int EASY = 3;     void doStuff(int t);
    }
      

  5.   

    因为接口中的声明是public的啊,不能在实现类中把它的作用域给缩小的,不加public,仅在当前包下使用。
    而接口中定义的是public中,是在所有的地方都可以使用的,这样就违背了接口中的声明。