title: Why an instance of inherited class can't access to protected member of base class in different package
body: <p>I have 3 class A, B, C :</p>
  
  <pre><code>package com.training.protectedclass.A;
  
  public class A
  {
      protected int   value;
  }
  </code></pre>
  
  <p></p>
  
  <p></p>
  
  <pre><code>package com.training.protectedclass.B;
  import com.training.protectedclass.A.A;
  
  public class B extends A
  {
      public void test()
      {
          this.value = 10;
          A a = new A();
          a.value = 12; //Error =&gt; The field A.value is not visible
      }
  }
  </code></pre>
  
  <p></p>
  
  <p></p>
  
  <pre><code>package com.training.protectedclass.C;
  
  import com.training.protectedclass.B.B;
  import com.training.protectedclass.A.A;
  
  public class C extends A
  {
      public void test()
      {           
          B b = new B();
          b.value = 45; //Error =&gt; The field A.value is not visible
      }
  }
  </code></pre>
  
  <p>When the inherited class exists in different package than the base class, it can't access the protected member of base class. But when all the three class exist in the same package the above errors disappear and the code is compiled without errors.</p>
  
  <p>Can anyone explain me the cause of each error launched in my code above?</p>
  
  <p>Thanks :) </p>