is A | has A |
Red is A Color: class Red extends Color{} class Blue extends Color{} class Yellow exrends Color{} |
She has A friend: class She{ private Person friend; } |
继承关系 (分为: 接口继承——扩展父类类型或功能 略 实现继承——实现公共代码的重用
1 class Red extends Color{ 2 3 public void sayHello(){ 4 5 System.out.print("大家好,"); 6 7 } 8 9 } 10 11 class Red extends Color{ 12 13 @OverWrite 14 15 public void sayHello(){ 16 17 super.sayHello(); 18 19 System.out.println("我叫red!"); 20 21 } 22 23 } 24 25 26 class Blue extends Color{ 27 29 @OverWrite 31 32 public void sayHello(){ 34 35 super.sayHello(); 37 38 System.out.println("我叫blue!"); 40 41 } 42 43 44 }
|
从属关系
|