Created
January 23, 2012 14:42
-
-
Save fcamblor/1663459 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Java puzzler on my Intellij issue today ... | |
Given following classes : | |
public class A { | |
public String foo(){ return "foo"; } | |
} | |
public class B { | |
public String bar(){ return "bar"; } | |
} | |
public class C { | |
A toto = new A(); | |
} | |
public class D { | |
B toto = new B(); | |
public void blah(){ | |
new C(){ | |
public void bleh(){ | |
System.out.println(toto.bar()); | |
} | |
}.bleh(); | |
} | |
} | |
What is displayed in console when we call : new D().blah() ? | |
1/ "foo" | |
2/ "bar" | |
3/ It doesn't compile | |
4/ There is an exception at runtime |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment