Tried to run vehicle problem, debug a bit but found the problem is at Car joe = new Car(1234567, 'R', 4);
public class Vehicle {
private int engineNum;
private char color;
public void setNum(int num) { engineNum=num; }
public void setColor(char color) { this.color = color; }
public void printVehicle() {
System.out.println("Engine No.: " + engineNum);
System.out.println("Vehicle Color: " + color);
}
class Car extends Vehicle {
private int doors;
public Car(int num, char color, int doors){
setNum(num);
setColor(color);
this.doors = doors;
}
public void printCar() {
System.out.println("=====Car Info=====");
printVehicle();
System.out.println("Car door no.: " + doors);
}
}
public static void main(String[] args) {
**Car joe = new Car(1234567, 'R', 4);**
Car jane = new Car(5678924, 'B', 5);
joe.setColor('W');
joe.printCar();
jane.printCar();
}
}
With message: No enclosing instance of type Vehicle is accessible. Must qualify the allocation with an enclosing instance of type Vehicle (e.g. x.new A() where x is an instance of Vehicle).