BlogtimeException

By Behrang Saeedzadeh (the 5th incarnation)

Java Quiz #1

, ,

What will this program print in the console when you run it?

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";
    }    
}

MacBeans, Part IIFunny NetBeans Bug

Write a comment

You must be logged in to write a comment. If you're not a registered member, please sign up.