Davey Lopez wrote:The only thing the tutorial isn't quite clear on is why they would need to be used if someone can give me an idea I would appreciate it
Upcasting (ie, casting to a superclass) is almost never needed, since any subclass (eg,
Dog)
is its superclass (eg,
Animal), so:
Animal a = new Dog();
is perfectly legal.
The simplest example I know of where a
downcast is normally
required is an
equals() method, because it takes an
Object, eg, for a
Dog:
HIH
Winston