Reputation:
If you declare an object like so:
Object x;
does it initialize as null
?
For example, will (x == null)
be true
?
Upvotes: 3
Views: 141
Reputation: 129507
If x
is a field, it will be null
by default. If it is a local variable, you have to explicitly initialize it before you use it. This is outlined in JLS §4.12.5: Initial Values of Variables.
Upvotes: 11
Reputation: 172438
member variables are initialized to null and local variables are not initialized and the initial value is set by you.
Note:- null is definitely a value. Its the value which doesnt refer to any object.
Upvotes: 1