标签:
1 public abstract class A{ 2 public abstract void method1(); 3 public void method2(){ 4 //A method2 5 } 6 } 7 public class B extends A{ 8 public void method1(){ 9 //B method1 10 } 11 } 12 public class C extends A{ 13 public void method1(){ 14 //C method1 15 } 16 }
1 public interface A{ 2 public void method1(); 3 public void method2(); 4 } 5 public class B implements A{ 6 public void method1(){ 7 //B method1 8 } 9 public void method2(){ 10 //B method2 11 } 12 } 13 public class C implements A{ 14 public void method1(){ 15 //C method1 16 } 17 public void method2(){ 18 //C method2 19 } 20 }
1 interface A{ 2 public void method2(); 3 } 4 interface B{ 5 public void method1(); 6 } 7 class C implements A,B{ 8 public void method1(){ 9 //C method1 10 } 11 public void method2(){ 12 //C method2 13 } 14 } 15 //可以如此灵活的使用C,并且C还有机会进行扩展,实现其他接口 16 A a=new C(); 17 B b=new C(); 18 abstract class A{ 19 public abstract void method1(); 20 } 21 abstract class B extends A{ 22 public abstract void method2(); 23 } 24 class C extends B{ 25 public void method1(){ 26 //C method1 27 } 28 public void method2() { 29 //C method2 30 } 31 }
标签:
原文地址:http://www.cnblogs.com/Coda/p/4442942.html