Java OCA OCP Practice Question 678

Question

How many of the types ArrayList, List, and Object can fill in the blank to produce code that compiles?

List v = new ___(); 
  • A. None
  • B. One
  • C. Two
  • D. Three


B.

Note

List is an interface and not a class. It cannot be instantiated.

While Object is a concrete class, it does not implement the List interface so it cannot be assigned to v.

If you were to add an explicit cast, it would compile and throw an exception at runtime.

Of the three options, only ArrayList can fill in the blank, so Option B is correct.




PreviousNext

Related