From a book:
What if you want to call a method that’s defined by a subclass from an object that’s referenced by a variable of the superclass? Suppose that the SoftBall class has a method named riseBall that isn’t defined by the Ball class. How can you call it from a Ball variable? One way to do that is to create a variable of the sub-class and then use an assignment statement to cast the object:"
Ball b = new SoftBall();
SoftBall s = (SoftBall)b;
// cast the Ball to a SoftBall
s.riseBall();
I don't understand this. Why can't I just directly call the method from the variable b? (The variable b in this case holds a Softball object). Why the casting?