- the code assumes both integer were initialized with 0 value. Does java always initialize variables for me? If so, with wich values are a boolean and a char initialized?
variable a is an instance variable and b is a static variable in the above code.
Static variables are initialized to default values when the class is loaded,if they are not explicitly initialized.
Instance variables are initialized to default values when the class is instantiated,if they are not explicitly initialized.
Local variables have to be initialized explicitly.if they are not initialized when they are instantiated at method invocation,compiler reports an error.
if a boolean variable is declared as static/instance variable then it is set to its default value ie false
Here is a list of datatypes and their defalut values
datatype default value
boolean false
char '\u0000'
Integer(byte,short,int,long) 0
Floating-point(float,double) +0.0F/0.0D
Object reference null
-bani