77问答网
所有问题
JAVA接口中不可以有静态方法吗
如题所述
举报该问题
推荐答案 推荐于2018-02-28
在jdk1.8中,接口里可以有静态方法,接口里的静态方法 必须要有body。
静态方法不需要实现。
public interface testInter {
void printme();
static void print_s(){
System.out.println("print in static method in interface");
}
}
class testInterImpl implements testInter{
public void printme() {
System.out.println("me");
}
}
public class TestMain {
public static void main(String[] args) {
System.out.println("123");
testInterImpl t = new testInterImpl();
t.printme();
testInter.print_s();
}
}
亲测,1.8可以。
温馨提示:答案为网友推荐,仅供参考
当前网址:
http://77.wendadaohang.com/zd/G8v3IWpG3vW383qNWIq.html
其他回答
第1个回答 2016-11-16
接口中每一个方法也是隐式抽象的,接口中的方法会被隐式的指定为 public abstract(只能是 public abstract,其他修饰符都会报错),所以不能含有静态代码块以及静态方法(用 static 修饰的方法)
相似回答
大家正在搜
相关问题
Java的接口interface中为什么不能定义静态方法st...
java接口中为什么不能有静态方法
JAVA 中接口可以有静态方法吗?
java 接口可以定义静态方法么
java语言中,接口里不能定义静态方法怎么理解?
JAVA接口类中不能用静态变量
Java的抽象类和接口里能不能有静态成员和静态方法?
java接口中可以有static 方法吗