?????????????????????????????????????????????????????????????????Java???????????????????????С???Щ????????????????????????????????????????????????????????????????????????????????У??????????????????????.?????????????????????????У???????????????????????????????????????????????????????????????????????????????????????????????Java?????????????????????????????????????????????????У??????????
??????? ???
??????????????????????????????????????????????????????У????????????????????????????????????????檔
????????????????????????????????????????????????????????????κξ??????????????????κ?????????洢?????????????????????????
interface CanFight {
void fight();
}
interface CanSwim {
void swim();
}
interface CanFly {
void fly();
}
public class ActionCharacter {
public void fight(){
}
}
public class Hero extends ActionCharacter implements CanFight??CanFly??CanSwim{
public void fly() {
}
public void swim() {
}
/**
* ????fight()????????и????????????????????
*/
}
?????????????
??????????y???????????????????к????????????????????????????????????е??????????????????????????????????????????????????????????????????????????????????????????????У??????????????????????????????????и????????????????
?????????????Father?????Mother??
public class Father {
public int strong(){
return 9;
}
}
public class Mother {
public int kind(){
return 8;
}
}
????????????????????Son??
public class Son {
/**
* ???????Father??
*/
class Father_1 extends Father{
public int strong(){
return super.strong() + 1;
}
}
class Mother_1 extends  Mother{
public int kind(){
return super.kind() - 2;
}
}
public int getStrong(){
return new Father_1().strong();
}
public int getKind(){
return new Mother_1().kind();
}
}
???????????
public class Test1 {
public static void main(String[] args) {
Son son = new Son();
System.out.println("Son ??Strong??" + son.getStrong());
System.out.println("Son ??kind??" + son.getKind());
}
}
----------------------------------------
Output:
Son ??Strong??10
Son ??kind??6
????????????????????????????????????????????????????????????????????????????????????и???Father???????Mother????????????????????????????????????????????????????????????????????????????????????????????????????????????????в?????????