title: java access modifier- visibility of attributes whose type is other class. why it is visible or not?
body: <p>below are some nesty example of java access modifiers. I can't clearly figure out answers when classes have attributes whose type is other classes.</p>
  
  <pre><code>package packageX;
  import packageY.*;
  
  public class A {
      public int x;
      private int y;
      protected int z;
  
      public A objA;
      public C objC;
  
      void test(){
          System.out.println(x);
          System.out.println(y);
          System.out.println(z);
  
          System.out.println(objA.x);
          System.out.println(objA.y);
          System.out.println(objA.z);
  
          System.out.println(objC.x);
          System.out.println(objC.y);//not visible
          System.out.println(objC.z);//?? why visible?
      }
  }
  
  class B{
      public A objA;
      public C objC;
  
      void test(){
          System.out.println(x);//not visible
          System.out.println(y);//not visible
          System.out.println(z);//not visible
  
          System.out.println(objA.x);
          System.out.println(objA.y);//not visible
          System.out.println(objA.z);
  
          System.out.println(objC.x);
          System.out.println(objC.y);//not visible
          System.out.println(objC.z);//?? why visible?
      }
  }
  
  
  
  package packageY;
  import packageX.*;
  
  public class C extends A{
      public A objA;
      public C objC;
  
      void test(){
          System.out.println(x);
          System.out.println(y);//not visible
          System.out.println(z);
  
          System.out.println(objA.x);
          System.out.println(objA.y);//not visible
          System.out.println(objA.z);//not visible//??? why not visible?
  
          System.out.println(objC.x);
          System.out.println(objC.y);//not visible//??? why visible?
          System.out.println(objC.z);
      }
  
  }
  
  class D{
      public A objA;
      public C objC;
  
      void test(){
          System.out.println(x);//not visible
          System.out.println(y);//not visible
          System.out.println(z);//not visible
  
          System.out.println(objA.x);
          System.out.println(objA.y);//not visible
          System.out.println(objA.z);//not visible
  
          System.out.println(objC.x);
          System.out.println(objC.y);//not visible
          System.out.println(objC.z);//not visible//??? why not visible
      }
  }
  </code></pre>
  
  <p>I can't understand few lines with //??? can you expain why the attributes are visible or not?  </p>