Skip to content

Commit 4713173

Browse files
committed
init
1 parent 2faca5e commit 4713173

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/cn/teachcourse/PolymorphicTest.java

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package cn.teachcourse;
22

3+
/**
4+
* Created by http://teachcourse.cn on 2018/03/22.
5+
*/
36
public class PolymorphicTest {
47

58
/**
@@ -13,18 +16,19 @@ public static void main(String[] args) {
1316
C c = new C();
1417
D d = new D();
1518

16-
System.out.println("1--" + a1.show(b));//打印:1--A and A
17-
System.out.println("2--" + a1.show(c));//打印:2--A and A
18-
System.out.println("3--" + a1.show(d));//打印:3--A and D
19-
20-
System.out.println("4--" + a2.show(b));//打印:4--B and A
21-
System.out.println("5--" + a2.show(c));//打印:5--B and A
22-
System.out.println("6--" + a2.show(d));//打印:6--A and D
23-
24-
System.out.println("7--" + b.show(b));//打印:7--B and B
25-
System.out.println("8--" + b.show(c));//打印:8--B and B
26-
System.out.println("9--" + b.show(d));//打印:9--A and D
19+
System.out.println("1--" + a1.show(b));// 打印:1--A and A
20+
System.out.println("2--" + a1.show(c));// 打印:2--A and A
21+
System.out.println("3--" + a1.show(d));// 打印:3--A and D
22+
23+
System.out.println("4--" + a2.show(b));// 打印:4--B and A
24+
System.out.println("5--" + a2.show(c));// 打印:5--B and A
25+
System.out.println("6--" + a2.show(d));// 打印:6--A and D
26+
27+
System.out.println("7--" + b.show(b));// 打印:7--B and B
28+
System.out.println("8--" + b.show(c));// 打印:8--B and B
29+
System.out.println("9--" + b.show(d));// 打印:9--A and D
2730
}
31+
2832
static class A {
2933
public String show(D obj) {
3034
return ("A and D");
@@ -46,11 +50,11 @@ public String show(A obj) {
4650
}
4751

4852
static class C extends B {
49-
53+
5054
}
5155

5256
static class D extends B {
53-
57+
5458
}
5559

5660
}

0 commit comments

Comments
 (0)