//不知道我理解的对不对
class Stone {//石头类
Stone(){
System.out.println("我是石头");
}
}
class StoneMach{//石头加工厂
public StoneSword mach( Stone st1)
{
return new StoneSword();
}
}
class StoneSword{//石刀
StoneSword()
{
System.out.println("哈哈,我是石刀");
}
public Lumber chop(Tree t)
{
System.out.println("我是砍树的方法");
return new Lumber();//石刀用传入的树加上砍方法生成木材
}
}
class Tree{//树
Tree(){
System.out.println("我是树!");
}
}
class chairFactory{//椅子加工厂
public Chair cFactory(Lumber lm){
System.out.println("我是椅子加工厂");
return new Chair();
}
}
class Lumber{//木材
Lumber()
{
System.out.println("我是木材");
}
}
class Chair{//椅子
Chair()
{
System.out.println("我是椅子");
}
}
public class Shitou{
public static void main(String[] args){
Stone s1=new Stone();
StoneMach sm=new StoneMach();
StoneSword ss=sm.mach(s1);
Tree t=new Tree();
Lumber lu=ss.chop(t);
chairFactory cf=new chairFactory();
Chair ch=cf.cFactory(lu);
}
} |
|