-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubClass.java
More file actions
39 lines (31 loc) · 716 Bytes
/
Copy pathSubClass.java
File metadata and controls
39 lines (31 loc) · 716 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
public class SubClass extends Father {
String name;
public void study() {
this.name = "学习";
System.out.println(this.name);
}
public void money() {
this.name = "没钱";
System.out.println(this.name);
}
public static void main(String[] args) {
SubClass sub = new SubClass();
sub.money();
sub.study();
Father fa = new Father();
fa.money();
Father faSec = (Father)sub;
faSec.name = "父类";
System.out.println(">>>" + faSec.name);
faSec.money();
//SubClass subSec = (SubClass)fa;
//subSec.money();
//subSec.study();
Father faSecT = new SubClass();
faSecT.money();
//SubClass.test(subSec);
}
public static void test(Father sub){
sub.money();
}
}