title: Constructor Chaining in Java
body: <p>I hava slight doubt regarding the Output of the Program of Constructor Chaining I showed Below:</p>
  
  <pre><code>class Cube {
  
      int length;
      int breadth;
      int height;
      public int getVolume() {
          return (length * breadth * height);
      }
      Cube() {
          this(10, 10);
          System.out.println("Finished with Default Constructor of Cube");
      }
      Cube(int l, int b) {
          this(l, b, 10);
          System.out.println("Finished with Parameterized Constructor having
                                      2 params of Cube");
      }
      Cube(int l, int b, int h) {
          length = l;
          breadth = b;
          height = h;
          System.out.println("Finished with Parameterized Constructor having
                                      3 params of Cube");
      }
  }
  
  public class SpecialCube extends Cube {
  
      int weight;
      SpecialCube() {
          super();
          weight = 10;
      }
      SpecialCube(int l, int b) {
          this(l, b, 10);
          System.out.println("Finished with Parameterized Constructor having
                                      2 params of SpecialCube");
      }
      SpecialCube(int l, int b, int h) {
          super(l, b, h);
          weight = 20;
          System.out.println("Finished with Parameterized Constructor having
                                      3 params of SpecialCube");
      }
      public static void main(String[] args) {
          SpecialCube specialObj1 = new SpecialCube();
          SpecialCube specialObj2 = new SpecialCube(10, 20);
          System.out.println("Volume of SpecialCube1 is : "
                  + specialObj1.getVolume());
          System.out.println("Weight of SpecialCube1 is : "
                  + specialObj1.weight);
          System.out.println("Volume of SpecialCube2 is : "
                  + specialObj2.getVolume());
          System.out.println("Weight of SpecialCube2 is : "
                  + specialObj2.weight);
      }
  }
  </code></pre>
  
  <p>OUTPUT:</p>
  
  <pre><code>Finished with Parameterized Constructor having 3 params of SpecialCube
  Finished with Parameterized Constructor having 2 params of SpecialCube
  Volume of SpecialCube1 is : 1000
  Weight of SpecialCube1 is : 10
  Volume of SpecialCube2 is : 2000
  Weight of SpecialCube2 is : 20
  </code></pre>
  
  <p>The doubt is regarding the OutPut that how "1000", "10", "2000" &amp; "20" are achiueved?</p>
  
  <p>In the main Class We have created two Objects : </p>
  
  <pre><code>SpecialCube specialObj1 = new SpecialCube();
  SpecialCube specialObj2 = new SpecialCube(10, 20);
  </code></pre>
  
  <p>First with "No Parameters" and Second with "Two Parameters", The First Constructor Cube() with "No Parameter" has only two values <code>this(10,10)</code> and the one with "Two Parameters" has the values</p>
  
  <pre><code>Cube(int l, int b) 
      {this(l, b, 10);}
  </code></pre>
  
  <p>I don't understand how the Below OutPuts are generated.</p>
  
  <pre><code>Volume of SpecialCube1 is : 1000
  Weight of SpecialCube1 is : 10
  Volume of SpecialCube2 is : 2000
  Weight of SpecialCube2 is : 20
  </code></pre>
  
  <p>Please Can anybody help me!</p>
  
  <p>Thanks,
  david</p>