首先先建立一個類學習
public class Father {
private Daughter daughter ;//擁有女兒屬性this
public Daughter getDaughter() {
return daughter;
}
public void setDaughter(Daughter daughter) {
this.daughter = daughter;
}get
//方法 :監督學習
public void supervisionLearn(){
System.out.println("快點作做業!");
this.daughter .response();
if(this.daughter instanceof PureDaughter){
PureDaughter pd=(PureDaughter)this.daughter;
pd.coquetry();
}
}io
}class
再建立一個父類方法
public class Daughter {
public void response(){
}static
}vi
女兒子類co
public class BoldDaughter extends Daughter{
public void response(){
System.out.println("忽的站起來,衝進了房間,狠狠地關上了門,唸到:真煩!");
}new
}
能夠再建立另外一個不一樣性格的女兒
最後main方法
public class TestMain {
public static void main(String[]args){
Father li=new Father();
PureDaughter doudou=new PureDaughter();
BoldDaughter lili=new BoldDaughter();
li.setDaughter(doudou);
li.supervisionLearn();
}
}