I didn't know that Java will actually assign a default value to variable that is declared as field variable, or as what you would refer as instance variable and static variable. For many years, I thought we will have to assign a default value somehow or we will get an error or some sort. So basically, the default value is automatically assigned when the field variable is declared. See the data types and their corresponding default values as below:
|int, short, byte
|String (or any object)
Noted that this is not the case with local variable or block variable!
In Java, if you have declared such variable without assiging value to it, it won't get assigned a default value like field variable. In fact, the compiler will throw an error if you try to use the variable in the application!
Well, I hope this helps! Adios, my friend!
Post was published on , last updated on .
Like the content? Support the author by paypal.me!