接口的实现、继承等
1 package test.interfacedemo; 2 import test.interfacedemo.Inter; 3 4 public class InterfaceDemo { 5 public static void main(String[] args){ 6 Inter o1 = new Foo(); //Foo实现接口Inter,类同于 向上造型 7 //通过变量o1可以调用接口Inter中定义的方法和常量 8 System.out.println(Inter.PI); 9 10 Inter3 t = new Boo(); //Boo实现接口Inter3 11 t.a(); 12 t.c(); 13 } 14 }
1 package test.interfacedemo; 2 3 public interface Inter{ //接口定义 4 public static final double PI = 3.14; 5 int NUM = 5; 6 public abstract void show(); 7 void say(); //省略public abstract 8 } 9 10 class Foo implements Inter{ 11 public void show(){} 12 public void say(){} 13 } 14 15 interface Inter1{ 16 public abstract void a(); 17 } 18 interface Inter2{ 19 public abstract void b(); 20 } 21 interface Inter3 extends Inter1{ 22 public abstract void c(); 23 } 24 25 abstract class Aoo{ 26 void d(){} 27 abstract void e(); 28 } 29 class Boo implements Inter3{ 30 void m(){} 31 public void a(){ 32 System.out.println("a"); 33 } 34 public void c(){ 35 System.out.println("c"); 36 } 37 } 38 class Coo implements Inter1,Inter2{ 39 public void a(){} 40 public void b(){} 41 } 42 class Doo extends Aoo implements Inter1,Inter2{ 43 void e(){} 44 public void a(){} 45 public void b(){} 46 }