黑马程序员技术交流社区
标题:
匿名对象作为参数传递分享
[打印本页]
作者:
q312092921
时间:
2016-3-28 22:49
标题:
匿名对象作为参数传递分享
class LanXiang {
public static void main(String[] args) {
new Cai(new WaJueJi(new DianNao(new Ren()))).cai();
}
}
class Ren {
public void yong(){
System.out.print("人用");
}
}
class DianNao {
Ren r ;
public DianNao(Ren r){
this.r = r;
}
public void kongZhi() {
r.yong();
System.out.print("电脑控制");
}
}
class WaJueJi {
DianNao dn;
public WaJueJi(DianNao dn){
this.dn = dn;
}
public void chao() {
dn.kongZhi();
System.out.print("挖掘机炒");
}
}
class Cai {
WaJueJi wjj;
public Cai(WaJueJi wjj){
this.wjj = wjj;
}
public void cai() {
wjj.chao();
System.out.print("菜");
}
}
复制代码
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2