一个演示继承关系的小程序

/**
 * 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);
	}
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值