What would be the output of the following code?
class A
{
B b;
A()
{
b=new B();
System.out.println(b.toString());
}
public
String toString()
{
return "I am A ";
}
}
class B
{
A a;
B()
{
a=new A();
System.out.println(a.toString());
}
public String toString()
{
return "I am B ";
}
}
public class
Test {
public static void main(String[] ar)
{
A a=new A();
B b=new B();
}
}
Compile error.
Prints "I am A I am B........."
endlessly.
Prints "I am B I am A........."
endlessly.
Goes into an endless loop.
I answered 4, but the correct ans is b. Can somebody tell me y?