In the constructor below, I have initialized only two of the variables, leaving some variables uninitialized explicitly.
As i have read, no argument constructor is created by the compiler if the constructor is provided by us.Then in such cases, since I have my own constructor so there is no default constructor which initializes variables p and q.
So, the logic should be if we try to access those uninitialized variables, then it should be a compile time error.However, the following code runs successfully.
The output is 5 10 0.0 0.0
How can we explain the output 0.0 and 0.0 since i have not declared them in the constructor ??
public class Rectangle {
int l, b;
double p, q;
public Rectangle(int x, int y) {
l = x;
b = y;
}
public static void main(String[] args) {
Rectangle obj1= new Rectangle(5,10);
System.out.println(obj1.l);
System.out.println(obj1.b);
System.out.println(obj1.p);
System.out.println(obj1.q);
}
}