Skip to content

Instantly share code, notes, and snippets.

@behrangsa
Created September 26, 2013 11:04
Show Gist options
  • Save behrangsa/6712702 to your computer and use it in GitHub Desktop.
Save behrangsa/6712702 to your computer and use it in GitHub Desktop.
Java Quiz #1
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";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment