Commit 965cfc7 1 parent 432470b commit 965cfc7 Copy full SHA for 965cfc7
File tree 2 files changed +39
-4
lines changed
2 files changed +39
-4
lines changed Original file line number Diff line number Diff line change
1
+ package 继承 ;
2
+ //final不能被重写 方法同名 返回类型相同 即使不写override也是重写
3
+ class fathers {
4
+ private void aa () {
5
+ System .out .println ("f----aa" );
6
+ }
7
+
8
+ final void aa1 () {
9
+ System .out .println ("f----aa1" );
10
+ }
11
+ }
12
+
13
+ public class Soner extends fathers {
14
+
15
+ void aa () {
16
+ System .out .println ("ssss----aa" );
17
+
18
+ }
19
+
20
+ //这个跟父类final方法没关系
21
+
22
+ int aa1 (int a ) {
23
+ System .out .println ("int----aa" );
24
+ return 1 ;
25
+ }
26
+ public static void main (String [] args ) {
27
+ // TODO Auto-generated method stub
28
+
29
+ Soner s = new Soner ();
30
+ s .aa ();
31
+ s .aa1 ();
32
+ s .aa1 (1 );//
33
+ }
34
+
35
+ }
Original file line number Diff line number Diff line change 1
1
package 继承 ;
2
2
3
- class 重载父类 {
3
+ class 重写父类 {
4
4
void a (){
5
5
System .out .println ("父类a" );
6
6
}
@@ -11,7 +11,7 @@ void b(){
11
11
}
12
12
13
13
14
- class 重载子类 extends 重载父类 {
14
+ class 重写子类 extends 重写父类 {
15
15
void a (){
16
16
System .out .println ("子类a" );
17
17
}
@@ -23,9 +23,9 @@ void b(){
23
23
}
24
24
}
25
25
26
- public class 重载的坑 {
26
+ public class 重写的坑 {
27
27
public static void main (String [] args ) {
28
- 重载父类 a = new 重载子类 ();
28
+ 重写父类 a = new 重写子类 ();
29
29
a .b ();
30
30
}
31
31
You can’t perform that action at this time.
0 commit comments