您的位置:首页 > 其它

继承的一个简单例子

2013-04-19 23:00 316 查看
package com;

public class Cleaner {
	public int price;

	public Cleaner(int price) {
		this.price = price;
	}

	public void clean() {
		System.out.println("可以去污");
	}

	public static void main(String[] args) {
		Soap s = new Soap();
		System.out.println("肥皂的价格:" + s.price);
		s.clean();
		s.shape();
		WashingPowder p = new WashingPowder();
		System.out.println("洗衣粉的价格:" + p.price);
		p.clean();
		p.shape();
	}

}

class Soap extends Cleaner {
	public Soap() {
		super(5);
	}

	public void shape() {
		System.out.println("呈块状");
	}
}

class WashingPowder extends Cleaner {
	public WashingPowder() {
		super(10);
	}

	public void shape() {
		System.out.println("呈粉末状");
	}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: