In Java, what would a variable of type int
hold if it was not initialized (I know that it will not let me compile if I used x
directly before initializing)?
say, if I did:
int x;
and how about
int[] x;
Thanks
The default value of primitive boolean is false .
In simple words, it means that whenever we are passing a non-primitive data type to a function or a variable, we are simply passing the address where the data is stored. The default value of reference variables is null.
In Java, the default value of char is “u0000”.
Instance variables will be defaulted to a 'reasonable' value. Local variables will contain garbage.
Read up on the topic here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With