Java Quiz #1
Saturday, 1. November 2008, 06:30:38
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"; } }









How to use Quote function: