Skip navigation.

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

How to use Quote function:

  1. Select some text
  2. Click on the Quote link

Write a comment

Comment
(BBcode and HTML is turned off for anonymous user comments.)

If you can't read the words, press the small reload icon.


Smilies