Is it possible to make every class that extends another class have the same variable?
public abstract class Plant {
public static List<Plant> allPlants;
}
public class Tomato extends Plant {
public static List<Tomato> Tomatoes;
}
public class Potato extends Plant {
public static List<Potato> Potatoes;
}
// In another class...
new Potato();
new Tomato();
Plant.allPlants; // shows both the new potato and tomato
Potato.Potatoes; // shows only the new potato
Tomato.Potatoes; // Nothing
Tomato.allPlants; // Nothing
I am not so worried about having the allPlants
list, but I want it so that I can only access the list of specific plants from its class. Am I going to have to write out all of these lists or is there a better way of doing it?