This is a homework assignment that I've been researching for over 2 hours and I still can't get a decent answer, so I would appreciate any help.
Suppose that Bicycle is a subclass of Vehicle.
Is the parameterized interface List<Bicycle>
a subinterface of List<Vehicle>
? Explain briefly.
My issues are:
I thought you couldn't even have lists in interfaces, only methods.
How can a list be an interface, let alone a subinterface?
What is this question even asking, in plain English? :/
Thanks in advance!
You are not HAVING a List
in an interface, List
itself is an
interface.
List
of course IS an interface (LinkedList
and ArrayList
being the classes implementing it). List
just provides methods enough to describe a simple list, and ArrayList
and LinkedList
provide bodies of those method according to the implementation.
To explain the actual question, I'll jot down some facts first. (Sorry if I'm going too basic, but I'm doing it for the sake of completion.)
List<Vehicle>
means List is a parametrized interface which has been given Vehicle
as it's parameter. (Here it means each element of List
is a Vehicle
. i.e. it's a list OF vehicles).List<Bicycle>
is a subinterface of List<Vehicle>
. (i.e. if List<Bicycle>
extends List<Vehicles>
given the fact that Bicycle
extends Vehicle
.I suppose it should be enough for you to understand the question and partly the answer too..
Good luck.