-1
我試圖將我的Vehicle類擴展爲HumanPowered類 - 每小時有一個卡路里字段。這是我第一次嘗試擴展課程,所以我在這裏有點困惑。Java:擴展類
class Vehicle
{
String description;
String idNumber;
int numWheels;
public Vehicle(String aDescription, String aIdNumber, int aNumWheels)
{
description = aDescription;
idNumber = aIdNumber;
numWheels = aNumWheels;
}
void setDescription (String aDescription)
{
description = aDescription;
}
void setIdNumber (String aIdNumber)
{
idNumber = aIdNumber;
}
void setNumWheels (int aNumWheels)
{
numWheels = aNumWheels;
}
public String getDescription()
{
return description;
}
public String getIdNumber()
{
return idNumber;
}
public int getNumWheels()
{
return numWheels;
}
public String toString()
{
String result= String.format("ID: %s Description: %s Wheels: %d",idNumber,description,numWheels);
return result;
}
}
class humanPowered extends Vehicle
{
int calories;
public humanPowered(String aDescription, String aIdNumber, int aNumWheels, int aCalories) //Error here
{
description = aDescription;
idNumber = aIdNumber;
numWheels = aNumWheels;
calories = aCalories;
}
void setCalories (int aCalories)
{
calories = aCalories;
}
public int getCalories()
{
return calories;
}
public String toString()
{
String result= String.format("ID: %s Description: %s Wheels: %d Calories per Hour: %d",idNumber,description,numWheels, calories);
return result;
}
}
我得到說我的構造上面標記爲我humanPowered類錯誤「隱超構造車輛()是不確定的。必須明確地調用另一個構造。」我無法弄清楚我哪裏會出錯。感謝您的幫助!
複製完整的錯誤信息,粘貼它進入谷歌,點擊你得到的第一個結果。你走了,你有一個答案。 –