Created
February 18, 2015 15:18
-
-
Save shigemk2/dc303f84aac4680e3bef 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
| class TestInt extends Test { | |
| private int i; | |
| public TestInt(int i) { this.i = i; } | |
| public String foo() { | |
| if (i == 1) return "bar"; | |
| return super.foo(); | |
| } | |
| } | |
| class TestStr extends Test { | |
| private String s; | |
| public TestStr(String s) { this.s = s; } | |
| public String foo() { | |
| if (s.equals("1")) return "baz"; | |
| return super.foo(); | |
| } | |
| } | |
| abstract class Test { | |
| public String foo() { return "?"; } | |
| public static void main(String[] args) { | |
| System.out.println(new TestInt( 0 ).foo()); | |
| System.out.println(new TestInt( 1 ).foo()); | |
| System.out.println(new TestStr("0").foo()); | |
| System.out.println(new TestStr("1").foo()); | |
| } | |
| } |
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
| class TestInt(i :Int) extends Test { | |
| override def foo(): String = { | |
| if (i == 1) return "bar" | |
| super.foo() | |
| } | |
| } | |
| class TestStr(s :String) extends Test { | |
| override def foo(): String = { | |
| if (s.equals("1")) return "baz" | |
| super.foo() | |
| } | |
| } | |
| class Test { | |
| def foo() = "?" | |
| } | |
| object Test { | |
| def main(args: Array[String]) { | |
| println(new TestInt( 0 ).foo()); | |
| println(new TestInt( 1 ).foo()); | |
| println(new TestStr("0").foo()); | |
| println(new TestStr("1").foo()); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment