title: Example for safe and unsafe downcast?
body: <p>When is a downcast unsafe and safe?</p>
  
  <p>Safe(think so) : <a href="http://www.linuxtopia.org/online_books/programming_books/thinking_in_java/TIJ309_014.htm" rel="nofollow">source - [here]
  </a></p>
  
  <pre><code>class Useful {
    public void f() {}
    public void g() {}
  }
  
  class MoreUseful extends Useful {
    public void f() {}
    public void g() {}
    public void u() {}
    public void v() {}
    public void w() {}
  }
  
  public class RTTI {
    public static void main(String[] args) {
      Useful[] x = {
        new Useful(),
        new MoreUseful()
      };
      x[0].f();
      x[1].g();
      // Compile time: method not found in Useful:
      //! x[1].u();
      ((MoreUseful)x[1]).u(); // Downcast/RTTI
      ((MoreUseful)x[0]).u(); // Exception thrown
    }
  } 
  </code></pre>
  
  <p>Can anyone give example for a unsafe downcast?</p>