/**
* Title:树继承
* Description:使用继承类,柳树就是树
* @author fan
*
*/
public class MyOsier extends MyTree{
/**
* 重写过树的树叶
*/
public void leaf(){
super.leaf();
String sShape = "长形";
super.print("形状:"+sShape);
}
/**
* 扩展树的花
*/
public void flower(){
print("哈哈,柳树没有花");
}
/**
* 主方法
* @param args
*/
public static void main(String[] args){
MyOsier o = new MyOsier();
MyTree t = new MyTree();
t.print("树的根");
t.root();
t.print("树的树干");
t.bolo();
t.print("树的树枝");
t.branch();
t.print("树的树叶");
t.leaf();
o.print("柳树的跟");
o.root();
o.print("柳树的树干");
o.bolo();
o.print("柳树的树枝");
o.branch();
o.print("柳树的树叶");
o.leaf();
o.print("柳树的花");
o.flower();
}
}
class MyTree{
/**
* 树的树根
*/
public void root(){
String sSite = "土壤中";
String sFunction = "吸收养分";
print("位置:"+sSite);
print("功能:"+sFunction);
}
/**
* 树的树干
*/
public void bolo(){
String sSite = "地面";
String sFunction = "传递养分";
print("位置:"+sSite);
print("功能:"+sFunction);
}
/**
* 树的树枝
*/
public void branch(){
String sSite = "树干上";
String sFunction = "传递养分";
print("位置:"+sSite);
print("功能:"+sFunction);
}
/**
* 树的树叶
*/
public void leaf(){
String sSite = "树梢";
String sFunction = "光合作用";
String sColor = "绿色";
print("位置:"+sSite);
print("功能:"+sFunction);
print("颜色:"+sColor);
}
/**
* 打印信息
* @param opera 打印信息的内容
*/
public void print(Object opera){
System.out.println(opera);
}
}
分享到:
评论