title: Why should I use general classes instead of specific classes
body: <p>I recently read that I should use general classes instead of specific classes when proramming.
  I can't figure out why it is suggested.</p>
  
  <p>example: Let's say that we have a class MyPanel that inherits from JPanel. MyPanel a non-inherited method called getLastChild.</p>
  
  <p>instead of:</p>
  
  <pre><code>MyPanel panel = new MyPanel():
  Component last = panel.getLastChild();
  </code></pre>
  
  <p>it is suggested to do this:</p>
  
  <pre><code>JPanel panel = new MyPanel();
  Component last = ((MyPanel)panel).getLastChild();
  </code></pre>
  
  <p>I don't see why I should choose the second one.</p>