Java OCA OCP Practice Question 1571

Question

Which of the following can fill in the blank to make the code compile?

public class News<___> {}
  • I. ?
  • II. News
  • III. Object
  • A. None of them
  • B. I
  • C. II and III
  • D. I, II, and III


C.

Note

When declaring a class that uses generics, you must specify a name for the formal type parameter.

Java uses the standard rules for naming a variable or class.

A question mark is not allowed in a variable name, making I incorrect.

While it is common practice to use a single uppercase letter for the type parameter, this is not required.

It isn't a good idea to use existing class names.

However, this is allowed, and Option C is correct.




PreviousNext

Related