-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOriginal.java
More file actions
57 lines (52 loc) · 1.83 KB
/
Original.java
File metadata and controls
57 lines (52 loc) · 1.83 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
package p1;
public class Original{
int n_friendly = 1;
private int n_private = 2;
protected int n_protected = 3;
public int n_public = 4;
void Access(){
System.out.println("****In same class, you can access ...");
System.out.println("friendly member "+n_friendly);
System.out.println("private member "+n_private);
System.out.println("protected member"+n_protected);
System.out.println("public member "+n_public);
}
}
class Derived extends Original{
void Access(){
System.out.println("**** 相同包的子类 ****");
System.out.println("friendly member"+n_friendly);
//System.out.println("private member "+n_private);
//不能访问
System.out.println("protected member"+n_protected);
System.out.println("public member "+n_public);
Original o = new Original();
System.out.println("**** 相同包的子类的其他对象 ****");
System.out.println("friendly member"+o.n_friendly);
//System.out.println("private member "+o.n_private);
//不能访问
System.out.println("protected member"+o.n_protected);
System.out.println("public member "+o.n_public);
}
}
class SamePackageClass{
void Access(){
Original o = new Original();
System.out.println("**** 相同包的其他类 ****");
System.out.println("friendly member "+o.n_friendly);
//System.out.println("private member "+0.n_private);
//不能访问
System.out.println("protected member"+o.n_protected);
System.out.println("public member "+o.n_public);
}
}
class AccessControl{
public static void main(String args[]){
Original o = new Original();
o.Access();
Derived d = new Derived();
d.Access();
SamePackageClass s = new SamePackageClass();
s.Access();
}
}