Java Reference
In-Depth Information
Listing 6-15. A Test Class Loated in the Same Package as the AccessLevel Class
// AccessLevelTest1.java
package com.jdojo.cls;
public class AccessLevelTest1 {
public static void main(String[] args) {
AccessLevel al = new AccessLevel();
// int a = al.v1; /* A compile-time error */
int b = al.v2;
int c = al.v3;
int d = al.v4;
System.out.println("b = " + b + ", c = " + c + ", d = " + d);
//al.m1(); /* A compile-time error */
al.m2();
al.m3();
al.m4();
/* Modify the values of instance variables */
al.v2 = 20;
al.v3 = 30;
al.v4 = 40;
System.out.println("\nAfter modifying v2, v3 and v4");
al.m2();
al.m3();
al.m4();
}
}
b = 200, c = 300, d = 400
Inside m2():
v1 = 100, v2 = 200, v3 = 300, v4 = 400
Inside m3():
v1 = 100, v2 = 200, v3 = 300, v4 = 400
Inside m4():
v1 = 100, v2 = 200, v3 = 300, v4 = 400
After modifying v2, v3 and v4
Inside m2():
v1 = 100, v2 = 20, v3 = 30, v4 = 40
Inside m3():
v1 = 100, v2 = 20, v3 = 30, v4 = 40
Inside m4():
v1 = 100, v2 = 20, v3 = 30, v4 = 40
Search WWH ::




Custom Search