title: How implement an inner class?
body: <p>I there,</p>
  
  <p>I have this scenario:</p>
  
  <pre><code>public class A{
    //attributes and methods
  }
  
  public class B{
    //attributes and methods
  
  }
  
  public class C{
    private B b;
    //other attributes and methods
  }
  
  public class D{
    private C c1, c2, c3;
    private List&lt;A&gt; a;
    //other attributes and methods
  }
  </code></pre>
  
  <p>Every class has its own file. However, I'd like to get classes A, B and C as inner classes of class D because I'm not using them throughout the program, just in a small part of it. How should I implement them? I've read about it, but I'm still not sure about what is the best alternative:</p>
  
  <p>Option 1, using static classes:</p>
  
  <pre><code>public class D{
    static class A{
      //attributes and methods
    }
  
    static class B{
      //attributes and methods
    }
  
    static class C{
      private B b;
      //other attributes and methods
    }
  
    private C c1, c2, c3;
    private List&lt;A&gt; a;
    //other attributes and methods
  }
  </code></pre>
  
  <p>Option 2, using an interface and a class that implements it.</p>
  
  <pre><code>public interface D{
    class A{
      //attributes and methods
    }
  
    class B{
      //attributes and methods
    }
  
    class C{
      private B b;
      //other attributes and methods
    }
  
  }
  
  public class Dimpl implements D{
    private C c1, c2, c3;
    private List&lt;A&gt; a;
    //other attributes and methods
  }
  </code></pre>
  
  <p>I'd like to know which approach is better in order to get the same behavior using the original scenario. Is it ok if I use Option 1 and use the classes like this?</p>
  
  <pre><code>public method(){
    List&lt;D.A&gt; list_A = new ArrayList&lt;D.A&gt;();
    D.B obj_B = new D.B();
    D.C obj_C1 = new D.C(obj_B);
    D.C obj_C2 = new D.C(obj_B);
    D.C obj_C3 = new D.C(obj_B);
  
    D obj_D = new D(obj_C1, obj_C2, obj_C3, list_A);
  }
  </code></pre>
  
  <p>Basicly, my concern is how the creation of inner classes will affect the outter class. In the original scenario, I first create the instances of classes A, B and C, then the instance of class D. Can I do the same with the options I mentioned?</p>