
在Java中,一个接口不能实现另一个接口。
BJXShop网上购物系统是一个高效、稳定、安全的电子商店销售平台,经过近三年市场的考验,在中国网购系统中属领先水平;完善的订单管理、销售统计系统;网站模版可DIY、亦可导入导出;会员、商品种类和价格均实现无限等级;管理员权限可细分;整合了多种在线支付接口;强有力搜索引擎支持... 程序更新:此版本是伴江行官方商业版程序,已经终止销售,现于免费给大家使用。比其以前的免费版功能增加了:1,整合了论坛
- 在Java中,接口本质上是一种特殊类型的类。与类一样,接口包含方法和变量。不同的是,接口始终是完全抽象的。
- 接口的定义与类类似,只是关键字interface代替了class,接口中声明的变量是static和final的,接口中定义的方法是public abstract方法。
- 一个接口可以扩展任意数量的接口,但一个接口不能实现另一个接口,因为如果实现了任何接口,则必须定义其方法,而接口永远不会有任何方法的定义。
- 如果我们尝试用另一个接口实现一个接口,在Java中会抛出编译时错误。
示例
interface MainInterface {
void mainMethod();
}
interface SubInterface extends MainInterface { // If we put implements keyword in place of extends, // compiler throws an error.
void subMethod();
}
class MainClass implements MainInterface {
public void mainMethod() {
System.out.println("Main Interface Method");
}
public void subMethod() {
System.out.println("Sub Interface Method");
}
}
public class Test {
public static void main(String args[]) {
MainClass main = new MainClass();
main.mainMethod();
main.subMethod();
}
}输出
Main Interface Method Sub Interface Method










