JDK8之前
public interface TestInterface {
//jdk 8之前只有两种方法
//成员变量
String name="你猜";
//成员方法(抽象方法)
void test();
}
JDK8之后
默认方法 必须使用default修饰,默认会被public修饰
/**
*1.jdk8后 默认方法 必须使用default修饰,默认会被public修饰
* 实例方法:对象的方法,必须使用实现类的对象看来访问
*/
default void test1(){
}
JDK9之后私有方法
使用private 修饰 私有方法只能在接口默认方法和其他的私有方法里边使用
/**
* 2.私有方法必须使用private修饰 (JDK9开始才支持)
* 默认方法,其他的私有方法调用
*/
private void test2(){
}
静态方法 必须使用static修饰 ,默认会被public修饰
/**
*3.静态方法,必须使用static修饰,默认会被public 修饰
*/
static void test3(){
}
现在全部的方法
public interface TestInterface {
//jdk 8之前只有两种方法
//成员变量
String name="你猜";
//成员方法(抽象方法)
void test();
/**
*1.jdk8后 默认方法 必须使用default修饰,默认会被public修饰
* 实例方法:对象的方法,必须使用实现类的对象看来访问
*/
default void test1(){
test2();
}
/**
* 2.私有方法必须使用private修饰 (JDK9开始才支持)
* 默认方法,其他的私有方法调用
*/
private void test2(){
}
/**
*3.静态方法,必须使用static修饰,默认会被public 修饰
*/
static void test3(){
}
}