Skip to content

Commit 965cfc7

Browse files
committed
update
1 parent 432470b commit 965cfc7

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

Java/src/继承/Soner.java

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
}

Java/src/继承/重载的坑.java Java/src/继承/重写的坑.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package 继承;
22

3-
class 重载父类{
3+
class 重写父类{
44
void a(){
55
System.out.println("父类a");
66
}
@@ -11,7 +11,7 @@ void b(){
1111
}
1212

1313

14-
class 重载子类 extends 重载父类{
14+
class 重写子类 extends 重写父类{
1515
void a(){
1616
System.out.println("子类a");
1717
}
@@ -23,9 +23,9 @@ void b(){
2323
}
2424
}
2525

26-
public class 重载的坑 {
26+
public class 重写的坑 {
2727
public static void main(String[] args) {
28-
重载父类 a = new 重载子类();
28+
重写父类 a = new 重写子类();
2929
a.b();
3030
}
3131

0 commit comments

Comments
 (0)