Sunday, 15 May 2011

Default Field Initialization in java

If you don't set a field explicitly in a constructor, it is automatically set to a default value: numbers to 0, Booleans to false, and object references to null. But it is considered poor programming practice to rely on this. Certainly, it makes it harder for someone to understand your code if fields are being initialized invisibly.
See difference between field variables and local variables.

No comments:

Post a Comment