-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOverLoad.java
More file actions
35 lines (26 loc) · 823 Bytes
/
OverLoad.java
File metadata and controls
35 lines (26 loc) · 823 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import static java.lang.System.*;
interface X { void foo(Object x); }
class A implements X {
public void foo(Object x) { out.println("A1" + x); }
public void foo(String x) { out.println("A2" + x); }
public void foo(Integer x) { out.println("A2" + x); }
public String toString() { return "A"; }
}
class B implements X {
public void foo(Object x) { out.println("B1" + x); }
public void foo(String x) { out.println("B2" + x); }
public void foo(Integer x) { out.println("B3" + x); }
public String toString() { return "B"; }
}
class OverLoad {
public static void main(String... args) {
X a = new A();
B b = new B();
a.foo("foo");
b.foo("bar");
a.foo(1);
b.foo(2);
new A().foo("fred");
new B().foo(a);
}
}