嘿,我只是在练习继承,我遇到了一个问题。我的汽车类(子类)中出现错误,即车辆(父类)中的变量不可见。我没有做任何事情来改变这一点,我什至不知道如何让它不可见。谁能帮我这个。
public class Vehicle
{
private String make, model, colour;
private int registrationNumber;
public Vehicle()
{
this.make = "";
this.model = "";
this.colour = "";
this.registrationNumber = 0;
}
public Vehicle(String make, String model, String colour,
int registrationNumber)
{
this.make = make;
this.model = model;
this.colour = colour;
this.registrationNumber = registrationNumber;
}
public String getMake()
{
return make;
}
public void setMake(String make)
{
this.make = make;
}
public String getModel()
{
return model;
}
public void setModel(String model)
{
this.model = model;
}
public String getColour()
{
return colour;
}
public void setColour(String colour)
{
this.colour = colour;
}
public int getRegistrationNumber()
{
return registrationNumber;
}
public void setRegistrationNumber(int registrationNumber)
{
this.registrationNumber = registrationNumber;
}
public String toString()
{
return "Vehicle [make=" + make + ", model=" + model + ", colour="
+ colour + ", registrationNumber=" + registrationNumber + "]";
}
}
public class Car extends Vehicle
{
private int doors;
private String shape;
public Car()
{
super();
this.doors = 0;
this.shape = "";
}
public Car(String make, String model, String colour, int registrationNumber)
{
super(make, model, colour, registrationNumber);
this.make = make;
this.model = model;
this.colour = colour;
this.registrationNumber = registrationNumber;
}
}
错误信息:
Description Resource Path Location Type
The field Vehicle.make is not visible Car.java /VehicleApp/src line 19 Java Problem
The field Vehicle.model is not visible Car.java /VehicleApp/src line 20 Java Problem
The field Vehicle.colour is not visible Car.java /VehicleApp/src line 21 Java Problem
The field Vehicle.registrationNumber is not visible Car.java /VehicleApp/src line 22 Java Problem