Monday, November 22, 2010

Java – fields of an object (instance variables, as opposed to local variables ) have default initial values in Java

Note that if you directly print out the value of a declared but uninitialized field that was declared as of type String, you would get “null” displayed on the screen instead of junk. Unlike local variables, which are not automatically initialized, every field has a default initial value – a value specified by Java when you do not initialize the field value.

**The default value for a field of type String is null.

No comments:

Post a Comment