else if (control.equals("Car") == true)
{
owner = (scanner.nextLine());
address = (scanner.nextLine());
phone = (scanner.nextLine());
email =(scanner.nextLine());
convertible= (scanner.nextBoolean());
color = (scanner.nextLine());
vehicleLot[i] = new car(owner, address, phone, email, convertible, color);
System.out.println(vehicleLot[i].getOwner());
System.out.println(vehicleLot[i].getAddress());
//System.out.println(vehicleLot[i].getColor());
}
The above code is in my main method. The line that is commented out throws out the error "cannot find symbol in the class vehicle". I am reading from a file and placing the information into the correct objects data fields. The array is an array of vehicles. From what I understand, an element of the array of vehicles can be a vehicle or any subclass of vehicle. Getters and setters methods are available for each respective class with subclass using the getters and setters for the parents class. Car is a subclass of vehicle. Why is it not trying to access cars methods first before trying vehicle when I just created the car object? Does the problem lie in my car constructor? car is static because it is a nested class and throws an error if you don't keep it static. Below is the summary of the car class.
static class Car extends vehicle
{
private boolean convertible;
private String color;
public Car()
{
}
public Car(String ownersName, String address, String phone, String email, boolean convertible, String color)
{
super.setOwner(ownersName) ;
super.setAddress(address);
super.setPhone(phone);
super.setEmail(email);
this.convertible = convertible;
this.color = color;
System.out.println(this.convertible);
}//Car class ends
The System.out.println prints out the correct value for that string, so I'm interested as to why the object wants to try and only use the class vehicle for its methods instead of class car and class vehicle. Here is vehicle if that helps.
public static class Vehicle
{
private String ownersName;
private String address;
private String phone;
private String email;
public Vehicle()
{
}
public Vehicle(String ownersName, String address, String phone, String email)
{
this.ownersName = ownersName;
this.address = address;
this.phone = phone;
this.email = email;
}
}//Vehicle class ends
== trueincontrol.equals("Car") == truesincecontrol.equals("Car")already returns a boolean