title: protected/public Inner Classes
body: <p>Can someone please explain to me what is the difference between <code>protected</code> / <code>public</code> <strong>Inner</strong> classes?</p>
  
  <p>I know that <code>public</code> inner classes are to avoid as much as possible (like explained in this <a href="http://www.onjava.com/pub/a/onjava/excerpt/HardcoreJava_chap06/index.html" rel="noreferrer">article</a>).</p>
  
  <p>But from what I can tell, there is no difference between using <code>protected</code> or <code>public</code> modifiers.</p>
  
  <p>Take a look at this example:</p>
  
  <pre><code>public class Foo1 {
   public Foo1() { }
  
   protected class InnerFoo {
    public InnerFoo() {
     super();
    }
   }
  }
  </code></pre>
  
  <p>...</p>
  
  <pre><code>public class Foo2 extends Foo1 {
   public Foo2() {
    Foo1.InnerFoo innerFoo = new Foo1.InnerFoo();
   }
  }
  </code></pre>
  
  <p>...</p>
  
  <pre><code>public class Bar {
   public Bar() {
    Foo1 foo1 = new Foo1();
    Foo1.InnerFoo innerFoo1 = foo1.new InnerFoo();
  
    Foo2 foo2 = new Foo2();
    Foo2.InnerFoo innerFoo2 = foo2.new InnerFoo();
   }
  }
  </code></pre>
  
  <p>All of this compiles and is valid whether I declare <code>InnerFoo</code> <code>protected</code> or <code>public</code>.</p>
  
  <p>What am I missing? Please, point me out a case where there's a difference in using <code>protected</code> or <code>public</code>.</p>
  
  <p>Thanks.</p>