What will this Java program run?

Take a look at the following Java sequence.  What will it print when run?  Enter your answer below in the comments:

 

======================================

public class Main {
    public static void main(String[] args) {        
        A a = new A();
        B b = null;
        try {            
            b = new B(a);
        } catch (Exception e) {}

        System.out.println(a.b);
        System.out.println(b);
        System.out.println(a.b == b);
    }
}

class A {    

    B b;    

    void setB(B b) {
        this.b = b;
        System.out.println(this.b);
    }    

    public String toString() {
        return b.toString();
    }
}

class B {    
    public B(A a) {
        a.setB(this);
        throw new RuntimeException();
    }

    public String toString() {
        return "B";
    }    
}
=====================================

Comments

comments

Posted in .