标签:void 多重继承 span java eve 性能 out 示例 str
引用知乎看到对接口的总结:
接口的定义如下:
[修饰符]interface<接口名>[extends<接口列表>] { 数据成员; //默认为public static final 成员函数; //默认为public abstract }
注意:接口可实现多重继承
接口的实现如下:
[访问修饰符]class 类名 implements[接口列表] { public 成员函数; }
1 interface InterFace0{ 2 void print(); 3 } 4 class InterFace1 implements InterFace0{ 5 public void print(){ 6 System.out.println("接口InterFace0实现"); 7 } 8 } 9 public class InterFace { 10 public static void main(String args[]){ 11 InterFace1 inter = new InterFace1(); 12 inter.print(); 13 } 14 }
接口的多重继承:
1.可以让一个接口去继承多个接口, 再用一个类来实现接口
1 interface InterFace0{ 2 void print0(); 3 } 4 interface InterFace1{ 5 void print1(); 6 } 7 //接口InterFace2继承InterFace0,InterFace1 8 interface InterFace2 extends InterFace0,InterFace1{ 9 } 10 //achieve类实现接口 11 class achieve implements InterFace2{ 12 public void print0(){ 13 System.out.println("InterFace0 print0方法"); 14 } 15 public void print1(){ 16 System.out.println("InterFace1 print1方法"); 17 } 18 } 19 public class InterFace { 20 public static void main(String args[]){ 21 achieve inter = new achieve(); 22 inter.print0(); 23 inter.print1(); 24 } 25 } 26 //输出: 27 //InterFace0 print0方法 28 //InterFace1 print1方法
2.也可以让一个类去继承多个接口
1 interface InterFace0{ 2 void print0(); 3 } 4 interface InterFace1{ 5 void print1(); 6 } 7 //类achieve继承InterFace0,InterFace1两个接口 8 class achieve implements InterFace0,InterFace1{ 9 public void print0(){ 10 System.out.println("InterFace0 print0方法"); 11 } 12 public void print1(){ 13 System.out.println("InterFace1 print1方法"); 14 } 15 } 16 public class InterFace { 17 public static void main(String args[]){ 18 achieve inter = new achieve(); 19 inter.print0(); 20 inter.print1(); 21 } 22 } 23 //输出: 24 //InterFace0 print0方法 25 //InterFace1 print1方法
标签:void 多重继承 span java eve 性能 out 示例 str
原文地址:http://www.cnblogs.com/luyanlong/p/6045145.html