1. class child {
2. int y = 12;
3. public void testIt() {
4. System.out.println("x is blank");
5.
6. // parent p = new parent();
7. //System.out.println("x in parent is " + p.x);
8. }
9. }
10.
11. class testProtect {
12. public void testAccess() {
13. int cx = child.y; <-- whats child here 1 doesn't get related to 2 either pass the reference of 1 or declare the variable as static
14. System.out.println("x is " + cx);
15. }
16. }
17.
18. public class Main {
19. public static void main(
String[] args) {
20. child childob = new child(); <-- you define new child object 1
21. childob.testIt();
22. testProtect tp = new testProtect(); <-- new
test project here 2
23. tp.testAccess();
24. }
25.
26. }