Skip to content

Instantly share code, notes, and snippets.

@shigemk2 shigemk2/Test.java
Created Feb 18, 2015

Embed
What would you like to do?
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());
}
}
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
You can’t perform that action at this time.