I am trying to instantiate objects of type Car through a constructor and I receive the following 2 errors: "The static field Vehicle.name should be accessed in a static way" and "The final field Vehicle.name cannot be assigned" on the constructor this. variables , except numWheels.
public interface Vehicle
{
String name = "";
int maxPassengers = 0;
int maxSpeed = 0;
}
public abstract class LandVehicle implements Vehicle
{
int numWheels = 0;
public abstract void drive();
}
public class Car extends LandVehicle
{
public void soundHorn()
{
System.out.println("Beep, beep!");
}
public void drive()
{
System.out.println("Vroom, vroom!");
}
public Car(String name, int maxSpeed, int maxPassengers, int numWheels)
{
this.name = name;
this.maxSpeed = maxSpeed;
this.maxPassengers = maxPassengers;
this.numWheels = numWheels;
}
}