-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccessTester.java
More file actions
27 lines (20 loc) · 959 Bytes
/
AccessTester.java
File metadata and controls
27 lines (20 loc) · 959 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
// File: AccessTester.java
// Package: demo.accessmodifiers
package demo.accessmodifiers;
public class AccessTester {
public static void main(String[] args) {
AccessModifiersDemo obj = new AccessModifiersDemo();
// Accessing public members - works without any restrictions
System.out.println("Public Variable: " + obj.publicVar);
obj.publicMethod();
// Accessing protected members - allowed within the same package
System.out.println("Protected Variable: " + obj.protectedVar);
obj.protectedMethod();
// Accessing default members - allowed within the same package
System.out.println("Default Variable: " + obj.defaultVar);
obj.defaultMethod();
// Trying to access private members - this will cause a compilation error if uncommented
// System.out.println("Private Variable: " + obj.privateVar); // Error
// obj.privateMethod(); // Error
}
}