Inheritance not working
Posted
by
Pendo826
on Stack Overflow
See other posts from Stack Overflow
or by Pendo826
Published on 2012-10-19T16:49:57Z
Indexed on
2012/10/19
17:00 UTC
Read the original article
Hit count: 137
java
|inheritance
Hey im just practicing inheritance and i encountered a problem. Im getting an error in my car class(sub-class) that the variables in Vehicle(parent) are not visible. i didnt do anything to change this and i dont even know how to make it invisible. Can anyone help me with this.
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 Car()
{
super();
this.doors = 0;
this.shape = "";
}
public Car(int doors, String shape, String make, String model, String colour, int registrationNumber)
{
super();
this.doors = doors;
this.shape = shape;
this.make = make;//Error
this.model = model;//Error
this.colour = colour;//Error
this.registrationNumber = registrationNumber;//Error
}
The error message:
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
© Stack Overflow or respective owner