Skip to content

Commit 4f788a0

Browse files
committed
多态的覆盖方法
1 parent d4a19be commit 4f788a0

File tree

7 files changed

+98
-16
lines changed

7 files changed

+98
-16
lines changed

.idea/compiler.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

objectTest/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
- [x] [polymorphic4__多态转型异常](src/main/java/com/cpucode/java/polymorphic/polymorphic4.java)
6565
- [x] [polymorphic5__多态转型异常判断](src/main/java/com/cpucode/java/polymorphic/polymorphic5.java)
6666
- [x] [polymorphic6__接口多态的综合案例](src/main/java/com/cpucode/java/polymorphic/polymorphic6)
67+
- [x] [多态的覆盖方法](src/main/java/com/cpucode/java/polymorphic/OverrideTest.java)
68+
6769

6870
- [返回object](#面对对象)
6971

objectTest/objectTest.iml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
3-
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">
3+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
44
<output url="file://$MODULE_DIR$/target/classes" />
55
<output-test url="file://$MODULE_DIR$/target/test-classes" />
66
<content url="file://$MODULE_DIR$">

objectTest/pom.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,20 @@
88
<artifactId>objectTest</artifactId>
99
<version>1.0-SNAPSHOT</version>
1010

11+
<build>
12+
<plugins>
13+
<!-- java编译插件 -->
14+
<plugin>
15+
<groupId>org.apache.maven.plugins</groupId>
16+
<artifactId>maven-compiler-plugin</artifactId>
17+
<version>3.2</version>
18+
<configuration>
19+
<source>1.8</source>
20+
<target>1.8</target>
21+
<encoding>UTF-8</encoding>
22+
</configuration>
23+
</plugin>
24+
</plugins>
25+
</build>
1126

1227
</project>

objectTest/src/main/java/com/cpucode/java/Abstract/abstract2/Main.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,5 @@
1-
/*
2-
* @由于个人水平有限, 难免有些错误, 还请指点:
3-
* @Author: cpu_code
4-
* @Date: 2020-09-13 16:47:12
5-
* @LastEditTime: 2020-09-13 17:37:44
6-
* @FilePath: \java\object\Abstract\abstract2\Main.java
7-
* @Gitee: [https://gitee.com/cpu_code](https://gitee.com/cpu_code)
8-
* @Github: [https://github.com/CPU-Code](https://github.com/CPU-Code)
9-
* @CSDN: [https://blog.csdn.net/qq_44226094](https://blog.csdn.net/qq_44226094)
10-
* @Gitbook: [https://923992029.gitbook.io/cpucode/](https://923992029.gitbook.io/cpucode/)
11-
*/
121
package com.cpucode.java.Abstract.abstract2;
132

14-
import object.Abstract.abstract2.Member;
15-
import object.Abstract.abstract2.QunZhu;
16-
173
import java.util.Scanner;
184
import java.util.ArrayList;
195

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.cpucode.java.polymorphic;
2+
3+
/**
4+
* @author : cpucode
5+
* @date : 2021/12/21 15:46
6+
* @github : https://github.com/CPU-Code
7+
* @csdn : https://blog.csdn.net/qq_44226094
8+
*/
9+
public class OverrideTest {
10+
public static void main(String[] args) {
11+
Base b = new Derived();
12+
b.f();
13+
b.g();
14+
}
15+
}
16+
17+
class Base {
18+
public Base() {
19+
g();
20+
}
21+
22+
public void f() {
23+
System.out.println("Base f");
24+
}
25+
26+
public void g() {
27+
System.out.println("Base g");
28+
}
29+
}
30+
31+
class Derived extends Base {
32+
public void f() {
33+
System.out.println("Derived f()");
34+
}
35+
36+
public void g() {
37+
System.out.println("Derived g()");
38+
}
39+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.cpucode.java.test.overrideTest;
2+
3+
/**
4+
* @author : cpucode
5+
* @date : 2021/12/21 15:33
6+
* @github : https://github.com/CPU-Code
7+
* @csdn : https://blog.csdn.net/qq_44226094
8+
*/
9+
public class OverrideTest {
10+
public static void main(String[] args) {
11+
Base b = new Derived();
12+
b.f();
13+
b.g();
14+
}
15+
}
16+
17+
18+
class Base {
19+
public Base() {
20+
g();
21+
}
22+
23+
public void f() {
24+
System.out.println("Base f");
25+
}
26+
27+
public void g() {
28+
System.out.println("Base g");
29+
}
30+
}
31+
32+
class Derived extends Base {
33+
public void f() {
34+
System.out.println("Derived f()");
35+
}
36+
37+
public void g() {
38+
System.out.println("Derived g()");
39+
}
40+
}

0 commit comments

Comments
 (0)