title: Overriding methods in java and then casting object to parent class behavior
body: <p>I have a parent class, A, and a child class, B, and B overrides a method, f, from A.</p>
  
  <pre><code>public class A
  {
      public String f()
      {
          return "A";
      }
  }
  
  public class B extends A
  {
      ...
      public String f()
      {
          return "B";
      }
  
      public static void main(String[] args)
      {
          B b = new B();
          A a = (A) b;
          System.out.println(b.f()); //prints: B
      }
  }
  </code></pre>
  
  <p>I create an object of type B, b, and cast that to type A and assign it to a variable of type A, a, and then call the method f on a. Now I'd expect the method of the parent class to be called since I'm working with an object of Type A but it doesn't, it calls the b version of the method(prints "B" instead of "A" in the code below).</p>
  
  <p>Why is it like this? Is it a design decision or a limit of technology?</p>