I am new to java and I doubt the initialization of the object.
What I know now:
Constructors are used to initialize instance variables, and if we do not explicitly code the constructor, a default constructor is provided that automatically provides default values for instance variables, such as 0 for int, etc.
My question is:
How does the following code work (I did not initialize the instance variable)?
I tried the base code as follows:
public class hello{
int i;
public hello()
{
}
public static void main(String args[])
{
System.out.println(new hello().i);
}
}
And the result was 0, but how? I did nothing in the constructor, and since I explicitly encoded the constructor, the default constructor should not be called (I know that I have the wrong concept, so please correct me).
, , .
!