Created
March 13, 2012 21:58
-
-
Save NickHeiner/2032032 to your computer and use it in GitHub Desktop.
Java compile time run time overloading
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
public class Main { | |
static class Root {} | |
static class Sub extends Root {} | |
public static void main(String[] args) { | |
foo(new Sub()); | |
Root r = new Sub(); | |
foo(r); | |
} | |
static void foo(Sub s) { | |
System.out.println("sub"); | |
} | |
static void foo(Root r) { | |
System.out.println("root"); | |
} | |
} | |
/* This prints: | |
sub | |
root | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment