日期:2014-05-20 浏览次数:20795 次
class Consumer {
protected float buyPrice;
protected void buyGoods(){};
}
class Producer {
protected float cost;
protected void produce(){};
}
/**
*Java实现“多继承”
*@author androidyue
*Last Modified:2011-12-13 上午11:00:25
*/
public class InnerClassDemo extends Producer {
public ConsumerBuyer buyer;
public void desribeMySelf(){
System.out.println("使用Java模拟多继承");
this.produce();
this.buyer=new ConsumerBuyer();
this.buyer.buyGoods();
}
public Consumer getConsumer(){
return buyer;
}
@Override
protected void produce() {
this.cost=100f;
System.out.println("我是生产者,我以每件"+this.cost+"RMB的成本生产一件产品,然后以20000元价格对外出售");
}
class ConsumerBuyer extends Consumer{
@Override
protected void buyGoods() {
this.buyPrice=0f;
System.out.println("我是消费者,我以"+this.buyPrice+"RMB 买了一件售价20000元的商品,不信吧,因为我也是生产者!^_^");
}