this is a 2 part question.
I have two classes: Animal and Vehicle which I'll be instantiating as objects. Animal contains two instance variables: numLegs and animalName, and Vehicle contains one instance variable: numTires, both classes contain getters and setters.
I have a generic class Box that holds either an Animal or a Vehicle.
Suppose I want to create an Arraylist of boxes. Every Box in said Arraylist will hold exclusively type Animal or exclusively type Vehicle.
e.g: In the case of exclusively animals, this will look something to the effect of:
List<Box<Animal>> list = new ArrayList<Box<Animal>>();
list.add( new Box<Animal>( new Animal( "fluffy", 4 ) ) );
(1). What should the box class look like?
also, suppose I want to perform a getter on an animal from the list.
Such as: System.out.println(list.get(0).getName());
(2). how would I go about this properly?
AnimalandVehicleis just confusing. This is why you are having a hard time coming up with a good solution. If the two classes having a common class then just use that. If they have nothing in common then I suggest using a different list for each.