title: How array works internally in Java?
body: <p>This query is posted to basically understand points like</p>
  
  <ul>
  <li><p>An object is class instance or an array;</p></li>
  <li><p>An array is a subclass of <code>Object</code> class;</p></li>
  <li><p>Everything that is instantiated other than primitive is an object in Java.</p></li>
  </ul>
  
  <p>Here is my understanding of working with arrays in Java.</p>
  
  <p>Considering the below program,</p>
  
  <pre><code>/* dummy.java */
  class C {
      private int i; 
      public C() {
          i = 1;
          System.out.println("Am in constructor");
      }
  }
  public class dummy {
      public static void main(String[] args) {
          C[] c = new C[2]; // Line 11
          c[0] = new C();
          System.out.println(c);
      }
  }
  </code></pre>
  
  <p>An object of type <code>class [LC</code> is created in run-time after running,</p>
  
  <pre><code>C[] c = new C[2]; //Line 11
  </code></pre>
  
  <p>In the above code. <code>class [LC</code> is an immediate subclass of <code>Object</code> class. Reference variable <code>c</code> points to this object (shown in red boundary below) after running <code>Line 12</code> in the above code. Reference variables sit in stack and an object of type <code>class C</code> will go in heap.</p>
  
  <p><img src="https://i.stack.imgur.com/ZyhTv.png" alt="enter image description here"></p>
  
  <p>For a below change of <code>line 11 &amp; 12</code> in the above code</p>
  
  <pre><code>C[][] c = new C[2][2];
  c[0][0] = new C();
  </code></pre>
  
  <p>will make the representation as shown below.</p>
  
  <p><img src="https://i.stack.imgur.com/hkj0P.png" alt="enter image description here"></p>
  
  <p>Is my understanding correct? If yes, Can you please explain more on usage of <code>class [LC</code> in run time to instantiate an object?</p>
  
  <p>Note: <code>C[].class</code> gives the actual type in run-time, which is <code>class [LC</code>.</p>