继承,派生自派生类

时间:2013-03-28 04:42:39

标签: java inheritance

我正在尝试从已经从另一个类派生的类创建一个类。 (有点令人困惑)它在最新的“PricedApt”类中添加了一个额外属性,即“价格”。所需的构造函数调用如下

   PricedApt p = new PricedApt("jill", 900, true, "jack", 1050.00);

该类缺少其构造函数,我试图创建它,但不确定是什么错误。

这是(已派生(第二)类)

public class RentalApt extends Apartment{

      private String tenant;
      private boolean rented;

      public RentalApt(String owner, int size, boolean rented, String who){
        super(owner,size);
        tenant = who;
        this.rented = rented;
      }

我尝试过的(第三)课程的代码是

public class PricedApt extends RentalApt {

private double price;

public PricedApt(String owner, int size, boolean rented, String who, double priceTag) {
  super(owner,size,who);
  price = priceTag;
}

}

任何人都可以指出我正确的方向,我做错了什么?我收到的编译错误是找不到符号(第2行第3列)。

1 个答案:

答案 0 :(得分:6)

例如,RentalApt有一个四参数构造函数,但它的子类PricedApt只用三个参数调用super()。

尝试更改

super(owner,size,who);

为:

super(owner,size,rented,who);