首先先创建一个类
public class Father {
private Daughter daughter ;//拥有女儿属性
public Daughter getDaughter() {
return daughter;
}
public void setDaughter(Daughter daughter) {
this.daughter = daughter;
}
//方法 :监督学习
public void supervisionLearn(){
System.out.println("快点做作业!");
this.daughter .response();
if(this.daughter instanceof PureDaughter){
PureDaughter pd=(PureDaughter)this.daughter;
pd.coquetry();
}
}
}
再创建一个父类
public class Daughter {
public void response(){
}
}
女儿子类
public class BoldDaughter extends Daughter{
public void response(){
System.out.println("忽的站起来,冲进了房间,狠狠地关上了门,念到:真烦!");
}
}
可以再创建另一个不同性格的女儿
最后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();
}
}