1. You create a new reference variable and assign a new B object to it. You can only invoke methods implemented by A on the B object.
2. You create a new reference variable, which refers to exactly the same object as the first variable
Concluding: You've just created 1 object, and two variables referring to that object!
There are many cases in which you'd want to use upcasting. F.e. when you want to do some generic things for all subclasses of a particular class.
Are you sure you're talking about upcasting? Since upcasting is always implicit. Am I wrong here?
Joined: Mar 07, 2012
Here I created an Object of Type B.But when I assigned it to superclass Object reference(which is a1) the upcating happened automatically.
although it was a B type object now it will behave like a1.It lost its specific Properties other than the generic.
Then I performed the downcast to obtain the lost specific properties of the Object of type B.