Skip to content

Instantly share code, notes, and snippets.

@fcamblor
Created January 23, 2012 14:42
Show Gist options
  • Save fcamblor/1663459 to your computer and use it in GitHub Desktop.
Save fcamblor/1663459 to your computer and use it in GitHub Desktop.
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