Java OCA OCP Practice Question 227

Question

Which of the following is true about primitives?

  • A. You can call methods on a primitive.
  • B. You can convert a primitive to a wrapper class object simply by assigning it.
  • C. You can convert a wrapper class object to a primitive by calling valueOf().
  • D. You can store a primitive directly into an ArrayList.


B.

Note

Option B is an example of autoboxing.

Java will automatically convert from primitive to wrapper class types and vice versa.

Option A is incorrect because you can only call methods on an object.

Option C is incorrect because this method is used for converting to a wrapper class from a String.

Option D is incorrect because autoboxing will convert the primitive to an object before adding it to the ArrayList.




PreviousNext

Related