Given the following class declaration:
class ClassA<U> implements Comparable<U> { public int compareTo(U a) { return 0; } }
Which class declarations below will compile without errors?.
Select the three correct answers.
(a) class ClassB<U,V> extends ClassA<R> {} (b) class ClassC<U,V> extends ClassA<U> {} (c) class ClassD<U,V> extends ClassA<V, U> {} (d) class ClassE<U> extends ClassA<Comparable<Number>> {} (e) class ClassF<U extends Comparable<U> & Serializable> extends ClassA<Number> {} (f) class ClassG<U implements Comparable<U>> extends ClassA<Number> {} (g) class ClassH<U extends Comparable<U>> extends ClassA<? extends Number> {} (h) class ClassI<U extends String & Comparable<U>> extends ClassA<U> {} (i) class ClassJ<U> extends ClassA<Integer> implements Comparable<Number>{}
(b), (d), and (e)
(a) R cannot be resolved.
(b) Ok.
(c) The ClassA
is parameterized with only one type parameter.
(d) Ok.
(e) Ok.
The declaration says that the parameterized type ClassA<Number>
is the super type of ClassF<U>
for any concrete type U that satisfies the constraint U extends Comparable<U> & Serializable.
(f) The keyword implements cannot be used to specify bounds.
(g) A wildcard cannot be used to specify the type parameter for the superclass.
(h) String is Comparable<String>, therefore, Comparable cannot be implemented more than once with different arguments.
(i) From the declaration, superclass ClassA<Integer>
implements Comparable<Integer>.
Subclass ClassJ
thus implements Comparable<Integer>.
However, Comparable cannot be implemented more than once with different arguments.