Java OCA OCP Practice Question 3001

Question

Consider the following definitions:

interface Printable {}
interface Shape 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 Shape to be the super type from which all type arguments must be derived?.

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


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 Shape can be used as a replacement for T.

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




PreviousNext

Related