title: Accessing a protected variable from a subclass outside package
body: <p>I have gone through so many websites which explains about access specifiers in java such as <a href="http://javapapers.com/core-java/access-modifiers-in-java-explain/" rel="noreferrer">java papers</a>, <a href="http://xahlee.info/java-a-day/access_specifiers.html" rel="noreferrer">java's access specifiers</a>, and many other stackoverflow questions like <a href="https://stackoverflow.com/questions/9867976/difference-between-the-default-access-specifier-and-protected-access-specifier-i">here</a>.</p>
  
  <p>All these guys explained that the protected member can be accessed by any subclass(also by the subclass out of package) and can be accessed by the package level classes.</p>
  
  <p>While experimenting on protected members, I found out that I'm unable to access a protected member from a subclass outside package.</p>
  
  <p>Check the code below. A public class with protected members:</p>
  
  <pre><code>package com.One;
  
      public class ProVars {
  
      protected int i = 900;
  
      protected void foo()
      {
          System.out.println("foo");
      }
  
  }
  </code></pre>
  
  <p>Another public class in different package trying to access protected member:</p>
  
  <pre><code>package com.Two;
  
  import com.One.ProVars;
  
  public class AnotherClass extends ProVars {
  
      public static void main(String[] args) {
          ProVars p = new ProVars();
          System.out.println(p.i);//the field ProVars.i is not visible(Compilation Error)
                  p.foo();//the method foo() from the type ProVars is not visible
  
      }
  }
  </code></pre>
  
  <p>Any explanation is appreciated.</p>