Important Java Mcq 1

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

Answer

B. It defaults to null.

Explanation:

An instance variable can be a variable of the type object. For such variables, the default value is null. (In particular, since Strings are objects, their default value is null.)

Related MCQs
Aniket Malik

Aniket Malik

CERTIFIED TUTOR/TRAINER WITH 300+ REVIEWS

Facing difficulty with

this concept?