Java OCA OCP Practice Question 131

Question

Which is correct about an instance variable of type String?

  • A. It defaults to an empty string.
  • B. It defaults to null.
  • C. It does not have a default value.
  • D. It will not compile without initializing on the declaration line.


B.

Note

Instance variables have a default value based on the type.

For any non-primitive, including String, that type is a reference to null.

Option B is correct.

If the variable was a local variable, Option C would be correct.




PreviousNext

Related