-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParent.java
More file actions
28 lines (25 loc) · 890 Bytes
/
Parent.java
File metadata and controls
28 lines (25 loc) · 890 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
package chap_07.chap_07_21_Example1;
public class Parent {
// 1) 접근 제어자별 멤버 변수 선언
public int publicValue;
protected int protectedValue;
int defaultValue;
private int privateValue;
public void method() {
// 2-1) 같은 클래스에서 멤버 변수에 접근할 경우
System.out.println(publicValue);
System.out.println(protectedValue);
System.out.println(defaultValue);
System.out.println(privateValue);
}
}
class Example {
public static void main(String[] args) {
Parent p = new Parent();
// 2-2) 같은 패키지에서 멤버 변수에 접근할 경우
System.out.println(p.publicValue); // 0
System.out.println(p.protectedValue); // 0
System.out.println(p.defaultValue); // 0
// System.out.println(p.privateValue); -> 에러 발생
}
}