Created
September 26, 2013 11:04
-
-
Save behrangsa/6712702 to your computer and use it in GitHub Desktop.
Java Quiz #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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