打字猴:1.700475716e+09
1700475716 this.product.beProducted();
1700475717
1700475718 //然后销售
1700475719
1700475720 this.product.beSelled();
1700475721
1700475722 }
1700475723
1700475724 }
1700475725
1700475726 这里多了个有参构造,其目的是要继承的子类都必选重写自己的有参构造函数,把产品类传递进来,再看子类HouseCorp的实现,如代码清单29-11所示。
1700475727
1700475728 代码清单29-11 房地产公司
1700475729
1700475730 public class HouseCorp extends Corp{
1700475731
1700475732 //定义传递一个House产品进来
1700475733
1700475734 public HouseCorp(House house){
1700475735
1700475736 super(house);
1700475737
1700475738 }
1700475739
1700475740 //房地产公司很High了,赚钱,计算利润
1700475741
1700475742 public void makeMoney(){
1700475743
1700475744 super.makeMoney();
1700475745
1700475746 System.out.println(“房地产公司赚大钱了……”);
1700475747
1700475748 }
1700475749
1700475750 }
1700475751
1700475752 理解上没有多少难度,不多说,继续看山寨公司的实现,如代码清单29-12所示。
1700475753
1700475754 代码清单29-12 山寨公司
1700475755
1700475756 public class ShanZhaiCorp extends Corp{
1700475757
1700475758 //产什么产品,不知道,等被调用的才知道
1700475759
1700475760 public ShanZhaiCorp(Product product){
1700475761
1700475762 super(product);
1700475763
1700475764 }
1700475765
[ 上一页 ]  [ :1.700475716e+09 ]  [ 下一页 ]