- 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
Object reference null