title: Understanding Java's protected modifier
body: <p>I have a class called A in package1 and another class called C in package2. Class C extends class A.</p>
  <p>A has an instance variable which is declared like this:</p>
  <pre><code>protected int protectedInt = 1;
  </code></pre>
  <p>Here is the code for class A</p>
  <pre><code>package package1;
  
  public class A {
      
      public int publicInt = 1;
      private int privateInt = 1;
      int defaultInt = 1;
      protected int protectedInt = 1;
  
  }
  </code></pre>
  <p>And here is the code for class C:</p>
  <pre><code>package package2;
  import package1.A;
  
  public class C extends A{
  
      public void go(){
          //remember the import statement
          A a = new A();
          System.out.println(a.publicInt);
          System.out.println(a.protectedInt);
          
      }
  }
  </code></pre>
  <p>Eclipse underlines the last line in <code>C.go()</code> and says &quot;A.protectedInt&quot; is not visible. It seems that this conflicts with the definition of the &quot;protected&quot; keyword, given the Oracle documentation says:</p>
  <blockquote>
  <p>The protected modifier specifies that the member can only be accessed within its own package (as with package-private) and, in addition, by a subclass of its class in another package.</p>
  </blockquote>
  <p>What's going on here?</p>