Created
June 15, 2016 08:47
-
-
Save kohsuke/1a03c7fd834f2941a7f7ec784123e397 to your computer and use it in GitHub Desktop.
Java Puzzler of the day
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 Foo { | |
public static class A { | |
public int i = 1; | |
} | |
public static class B extends A { | |
public int i = 2; | |
} | |
public static void main(String[] args) { | |
B b = new B(); | |
A a = b; | |
// Quiz: what do they print? | |
System.out.println(b.i); | |
System.out.println(a.i); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have often wondered if Java field dispatching (err lack of it... sorry for the spoiler) was chosen because of performance reasons or for semantic reasons.