Java OCA OCP Practice Question 103

Question

Give the following declarations:

Vector v1; 
Vector<String> v2; 

What are the advantages of using v2 rather than v1?

  • A. add anything other than a string to v2 results in a compiler error.
  • B. add anything other than a string to v2 causes a runtime exception to be thrown.
  • C. add anything other than a string to v2 causes a checked exception to be thrown.
  • D. add a string to v2 takes less time than adding one to v1.
  • E. The methods of v2 are synchronized.


A.

Note

v2 is a generic collection, so the compiler checks the types of arguments to add().




PreviousNext

Related