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; ...
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 }
|
從屬關係
|