title: Square and Rectangle Inheritance
body: <p>This is a question in-regards to basic inheritance in Java with two classes.</p>
  
  <p>We have two classes, with the first one being a <code>Rectangle</code>:</p>
  
  <pre><code>private double length;
  private double width;
  
  public Rectangle(double length, double width)
  {
      this.length = length;
      this.width = width;
  }
  </code></pre>
  
  <p>Next we have an extension class called <code>Square</code>, which extends <code>Rectangle</code>, so through <code>super()</code> we know that it uses the constructor of the <code>Rectangle</code> class.</p>
  
  <pre><code>private double side;
  
  public Square(double side)
  {
      super(side, side);
      this.side = side;
  }
  
  public void print()
  {
      System.out.println("I am a square of side " + side);
  }
  </code></pre>
  
  <p>This is our main:</p>
  
  <pre><code>Square b = new Square(6.0);
  Rectangle c = (Rectangle) b;
  c.print();
  </code></pre>
  
  <p>We create a object of the type <code>Square</code>, which would contain two <code>side</code> variables the <code>double</code> <code>6.0</code></p>
  
  <p>Next, we cast <code>b</code> to <code>Rectangle</code> <code>c</code>, which is where my question comes in.</p>
  
  <p>Why would <code>c.print()</code> print out <code>I am a square of side 6.0</code>? </p>