-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTest.java
More file actions
137 lines (113 loc) · 2.21 KB
/
Test.java
File metadata and controls
137 lines (113 loc) · 2.21 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package com.tanhao.test;
abstract class Father{
static String famliyname = "James";
private String name = null;
private int age = 40;
private static int test;
/*
public Father(){}
public Father(String name,int age){
this.name = name;
this.age = age;
}
*/
public String getName() {
return name;
}
final public void setName(String name) {
this.name = name;
}
//protected abstract void setName(String name);
public void setAge(int age) {
this.age = age;
}
public int getAge() {
return age;
}
protected abstract void dosth();
protected void printname(){
System.out.println("famliyname:" + famliyname);
System.out.println("name:" + this.name);
System.out.println("age:" + this.age);
System.out.println("test:" + Father.getTest());
}
final void run(){
dosth();
printname();
}
public static int getTest() {
return test;
}
public static void setTest(int test) {
Father.test = test;
}
}
class SonA extends Father{
/*
public SonA(String name,int age){
super(name,age);
}
*/
@Override
protected void dosth() {
// TODO Auto-generated method stub
System.out.println("I am Son A!");
//SonA.setName("Jack");
//SonA.setAge(20);
SonA.setTest(30);
}
}
class SonB extends Father{
/*
public SonB(String name,int age){
super(name,age);
}
*/
@Override
protected void dosth() {
// TODO Auto-generated method stub
System.out.println("I am Son B!");
//SonB.setName("Jim");
//SonB.setAge(30);
SonB.setTest(20);
}
}
class SonC extends Father{
public SonC(){
super();
}
/*
public SonC(String name,int age){
super(name,age);
}
*/
@Override
protected void dosth() {
// TODO Auto-generated method stub
System.out.println("I am Son C!");
//SonC.setName("Json");
//SonC.setAge(30);
//SonC.setTest(20);
}
}
class Test{
public static void main(String args[]){
Father sonA = new SonA();
sonA.setName("Jim");
sonA.setAge(30);
sonA.run();
Father sonB = new SonB();
sonB.run();
Father sonC = new SonC();
sonC.run();
System.out.println("######");
SonA sonA1 = new SonA();
sonA1.setName("Jim");
sonA1.setAge(30);
sonA1.run();
SonB sonB1 = new SonB();
sonB1.run();
SonC sonC1 = new SonC();
sonC1.run();
}
}