定义:
接口中定义的成员变量,默认是常量;
接口中没有构造器;(因此接口不能直接创建对象)
接口中的方法默认是抽象方法(无方法体);
JDK8开始,接口新增的方法:
一、默认方法:必须使用default修饰,默认会被public修饰;
访问:必须使用实现类的对象来访问;
public interface Inter {
default void test1(){
System.out.println("默认方法");
}
}
二、静态方法:static修饰,必须用当前接口名进行调用;
public interface Inter {
static void test2(){
System.out.println("静态方法");
}
}
三、私有方法:private修饰,JDK9开始才有的,只能在接口内部被调用;
public interface Inter {
default void test1(){
System.out.println("默认方法");
test3();
}
private void test3(){
System.out.println("私有方法");
}
}