What's the need to use Upcasting in java?
<p>I've gone through most of the papers in the net, but I'm still not able to understand, why we have to use upcasting.</p>

<pre><code>class Animal 
{ 
    public void callme()
    {
        System.out.println("In callme of Animal");
    }
}

class Dog extends Animal 
{ 
    public void callme()
    {
        System.out.println("In callme of Dog");
    }

    public void callme2()
    {
        System.out.println("In callme2 of Dog");
    }
}

public class UseAnimlas 
{
    public static void main (String [] args) 
    {
        Dog d = new Dog();      
        Animal a = (Animal)d;
        d.callme();
        a.callme();
        ((Dog) a).callme2();
    }
}
</code></pre>

<p>You can consider this example for upcasting. What's the use of upcasting here? Both <code>d</code> and <code>a</code> giving the same output!</p>
