Eclipse创建Java接口及其内的抽象方法
实现接口实现类:
类:接口
或
类 implement 接口
,并在体内实现该方法。
定义业务逻辑时:
接口.接口方法
。
初始化方法:
接口=接口实现类
。
创建接口类
Eclipse
在接口中添加抽象方法
在接口中创建的普通抽象方法,只能是public
的,因为需要其他类在外部implement实现,如下所示。
public interface testInterface {
//如果是public的抽象方法,会提示“Illegal combination of modifiers for the private interface method unifiedMethodName; additionally only one of static and strictfp is permitted”
//如果是protected的抽象方法,会提示“Illegal modifier for the interface method unifiedMethodName; only public, private, abstract, default, static and strictfp are permitted”
public abstract void unifiedMethodName();
}