What is default value of local variables ?
Answer : Local variables stored on the stack and aren’t actually created until they have been initialized. If a local variable isn’t used then it doesn’t go on the stack. Member variables, however, are allocated in the heap, and so have a default placeholder (null reference or default primitive).
Please see below default values:
Data Type | Default Value (for fields) |
byte | 0 |
short | 0 |
int | 0 |
long | 0L |
float | 0.0f |
double | 0.0d |
char | ‘\u0000’ |
String (or any object) | null |
boolean | false |