Java OCA OCP Practice Question 3257

Question

Consider the following definitions:

interface Printable {}
interface Writable extends Printable {}

The following options provide definitions of a template class X.

Which one of the options specifies class X with a type parameter whose upper bound declares Writable to be the super type from which all type arguments must be derived?.

  • a) class X <T super Writable> { }
  • b) class X <T implements Writable> { }
  • c) class X <T extends Writable> { }
  • d) class X <T extends ? & Writable> { }


c)

Note

The keyword extends is used to specify the upper bound for type T; with this, only the classes or interfaces implementing the interface Writable can be used as a replacement for T.

Note that the extends keyword is used for any base type-irrespective of if the base type is a class or an interface.




PreviousNext

Related