Default value of variable in java

Variables declared inside a class are known as member variables (static or non static). These variables are initialized with their default value depending on the type of variable. For example variable of type int contains 0 by default, double variable contains 0.0, etc. The variables of primitive type contains 0 as a default value in a broader sense.

When variable is of any class type (non-primitive type), then it is known as reference variable, and it contains null value as a default value.

When member variables are final, they are blank until initialized.

You can set default value of member variables inthe class definition. For example
class Box
{
private int length=10, breadth=10, height=10;
...
}

Local variables (variables declared in a function or block), are blank until initialized.
There is no concept of garbage value like C and C++ variables.





What is the default value of variable in Java?
Tagged on: