File tree 7 files changed +98
-16
lines changed
src/main/java/com/cpucode/java
test/src/main/java/com/cpucode/java/test/overrideTest
7 files changed +98
-16
lines changed Original file line number Diff line number Diff line change 64
64
- [x] [ polymorphic4__ 多态转型异常] ( src/main/java/com/cpucode/java/polymorphic/polymorphic4.java )
65
65
- [x] [ polymorphic5__ 多态转型异常判断] ( src/main/java/com/cpucode/java/polymorphic/polymorphic5.java )
66
66
- [x] [ polymorphic6__ 接口多态的综合案例] ( src/main/java/com/cpucode/java/polymorphic/polymorphic6 )
67
+ - [x] [ 多态的覆盖方法] ( src/main/java/com/cpucode/java/polymorphic/OverrideTest.java )
68
+
67
69
68
70
- [ 返回object] ( #面对对象 )
69
71
Original file line number Diff line number Diff line change 1
1
<?xml version =" 1.0" encoding =" UTF-8" ?>
2
2
<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 " >
4
4
<output url =" file://$MODULE_DIR$/target/classes" />
5
5
<output-test url =" file://$MODULE_DIR$/target/test-classes" />
6
6
<content url =" file://$MODULE_DIR$" >
Original file line number Diff line number Diff line change 8
8
<artifactId >objectTest</artifactId >
9
9
<version >1.0-SNAPSHOT</version >
10
10
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 >
11
26
12
27
</project >
Original file line number Diff line number Diff line change 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
- */
12
1
package com .cpucode .java .Abstract .abstract2 ;
13
2
14
- import object .Abstract .abstract2 .Member ;
15
- import object .Abstract .abstract2 .QunZhu ;
16
-
17
3
import java .util .Scanner ;
18
4
import java .util .ArrayList ;
19
5
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments