我想知道如何在子类中使用超类构造函数,但需要在子类中实例化更少的属性。下面是两个班。我甚至不确定我目前是否在做正确的事情。在第二个类中,有一个错误提示“隐式超级构造函数PropertyDB()未定义,必须显式调用另一个构造函数。”请注意,此代码显然不完整,并且有代码被注释掉。构造函数和继承
public abstract class PropertyDB {
private int hectares;
private String crop;
private int lotWidth;
private int lotDepth;
private int buildingCoverage;
private int lakeFrontage;
private int numBedrooms;
private int listPrice;
//public abstract int getPricePerArea();
//public abstract int getPricePerBuildingArea();
public PropertyDB(int newHectares, String newCrop, int newLotWidth, int newLotDepth,
int newBuildingCoverage, int newLakeFrontage, int newNumBedrooms, int newListPrice){
hectares = newHectares;
crop = newCrop;
lotWidth = newLotWidth;
lotDepth = newLotDepth;
buildingCoverage = newBuildingCoverage;
lakeFrontage = newLakeFrontage;
numBedrooms = newNumBedrooms;
listPrice = newListPrice;
}
}
public class FarmedLand extends PropertyDB{
public FarmedLand(int newHectares, int newListPrice, String newCorn){
//super(270, 100, "corn");
hectares = newHectares;
listPrice = newListPrice;
corn = newCorn;
}
}
我仍然是初学者,但这似乎很有帮助。你能详细解释一下吗? – 2012-03-09 03:30:02