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);}
}
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);}
}
解决方案 »
- java指纹识别+谷歌图片识别技术==============贴出邮箱-送源码=================
- 很简单的字体选择框,连单击“退出”也没用?帮我看看吧
- 如何使树形控件个性显示
- 这是文件过滤的类,怎么实现象DOS里面通配符号。
- 为什么JFileChooser不能打开一个盘符?
- 新开通第一问:关于JNI原理。
- 由北京的搞JSP+数据库开发的吗 ?能告诉一下你们的薪水吗?
- 在JAVA中怎样通过事务来完成一组数据库操作
- 新手:各位大虾用什么工具编java?有人说vj++不好。
- java中equals与==
- 求教Java实现“气泡窗口”
- 问一个关于swing的问题,有没有见过ActionListener,MouseListener这两个事件冲突的?
无论其是否有public,方法声明都被认为是public的,所以在实现类中必须加上public,
否则会认为方法的可见性被降低而造成编译错误。
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来修饰这样就没错误了
那我刚才编译下面这段interface DeclareStuff {
public static final int EASY = 3; void doStuff(int t);
}
这样为什么不报错。
public static final,所以对于上面这个接口,这么写也是可以的,而且效果相同。
interface DeclareStuff {
int EASY = 3; void doStuff(int t);
}
而接口中定义的是public中,是在所有的地方都可以使用的,这样就违背了接口中的声明。