I expect the output of the below program to be:
Inside Static Block A
Inside A
Inside Constructor B
But the output is:
Inside Static Block A
Inside A
Inside A
Inside A
.
.
.
Inside A(Infinite times)
The code is:
public class First
{
public static void main(String args[])
{
A op=new A();
}
}
class A
{
private int a=100;
private int b;
A()
{
System.out.print("Inside A");
B obj=new B();
}
static
{
System.out.print("Inside Static Block A");
}
class B
{
B()
{
System.out.print("Inside Constructor B");
}
A o=new A();
}
}
Can someone please tell me why the output is so?
B obj=new B();andA o=new A();- what do you think this does?