Я пытался
Код: Выделить всё
Motor motor = new Motor();Код: Выделить всё
private Motor motor = new Motor();Ниже приведен мой код для PassCar
Ошибка гласит, что конструктор Motor не определен.
Код: Выделить всё
public class PassCar extends Vehicle{
private Motor motor = new Motor();// the error
private int numPass;
private boolean AC;
public PassCar(String make, String model, int year, double price, int numPass, boolean aC, Motor motor) {
super(make, model, year, price);
this.numPass = numPass;
AC = aC;
this.motor = motor;
}
public int getNumPass() {
return numPass;
}
public void setNumPass(int numPass) {
this.numPass = numPass;
}
public boolean isAC() {
return AC;
}
public void setAC(boolean aC) {
AC = aC;
}
public Motor getMotor() {
return motor;
}
public void setMotor(Motor motor) {
this.motor = motor;
}
public void description() {
System.out.print("In this application, a passenger car is an every day vehicle registered to an individual");
}
@Override
public String toString() {
String s = super.toString();
s += "PassCar numPass = " + numPass + ", AC = " + AC + ", motor = " + motor;
return s;
}
}
Код: Выделить всё
public class Motor {
private String name;
private int cylinders;
private int bhp;
private double displacement;
public Motor(String name, int cylinders, int bhp, double displacement) {
super();
this.name = name;
this.cylinders = cylinders;
this.bhp = bhp;
this.displacement = displacement;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getCylinders() {
return cylinders;
}
public void setCylinders(int cylinders) {
this.cylinders = cylinders;
}
public int getBhp() {
return bhp;
}
public void setBhp(int bhp) {
this.bhp = bhp;
}
public double getDisplacement() {
return displacement;
}
public void setDisplacement(double displacement) {
this.displacement = displacement;
}
@Override
public String toString() {
return "Motor name = " + name + ", cylinders = " + cylinders + ", bhp = " + bhp + ", displacement = " + displacement;
}
}
публичный класс VehicleTest {
Код: Выделить всё
public static void main(String[] args) {
PassCar p1 = new PassCar("Ford", "Mustang", 2016, 44500.0, 5, true, "EcoBoost", 6, 310, 2.3);
System.out.print(p1);
}
Подробнее здесь: https://stackoverflow.com/questions/553 ... y-instance
Мобильная версия