Java OCA OCP Practice Question 2390

Question

Which of the following statements are true about generic classes, interfaces, and methods?.

  • a If you define a generic class, you must define its corresponding raw class explicitly.
  • b On compilation, type information is erased from a generic class.
  • c A generic method can be defined within a generic class or a regular class.
  • d Generic interfaces might not accept multiple generic type parameters.


b, c

Note

Option (a) is incorrect.

A raw type doesn't include the generic information.

For the generic type List<T>, its raw type is List.

You don't need to define a raw type explicitly for any generic class or interface.

You can access the raw type of all the generic types.

Option (d) is incorrect.

Like generic classes, generic interfaces can define any number of generic type parameters.




PreviousNext

Related