I have a Vehicle superclass and then I have some subclasses to that one. I am trying to have an array list that adds objects from all of the subclasses into the same list, but I'm coming up short.
I currently have the list in my program class but I have moved it around a bit.
This is the code I have in Program:
ArrayList<Vehicles> Inventorie = new ArrayList<>();
public void setInventorie(Car newCar) {
Inventorie.add(newCar);
}
And this the code I have in Car:
public void addCar(){
System.out.println("Make: ");
Make = scan.nextLine();
System.out.println("RegNr");
regNr = scan.nextInt();
System.out.println("Year");
year = scan.nextInt();
setValue();
Car c1 = new Car(make, regNr, Year);
Program.setInventorie(c1);
}
In Car I am getting "Non-static method 'setInventorie(Project1.Vehicles)' cannot be referenced from static context."
I also had to comment out the main method or the compiler couldn't resolve the symbol Inventorie (name of array list).
Tried to explain my problem as best as I could, hope someone can help. And yes, I am new to this so it might seem really stupid but it's the best I could do.
Thanks