cannot understand the point of downcasting in the following code
Joined: May 28, 2008
how are you?
wanted to ask you why this code is using Downcasting (1st code fragment line 36-37)? i.e.
in the line below
should not the compiler dynamically 'find out' that it is dealing with a subclass of CurrentEmployee
and use the appropriate functions in that sub-class (BasePlusCommissionEmployee)?
Christophe Verré wrote:You usually do it to call methods that a class has, but that its interface/super class has not. Methods getBaseSalary and setBaseSalary are called. Are these methods also in Employee ?
yes, i believe they are in the Employee class
Joined: Oct 13, 2005
Is that example from Deitel and Deitel? It looks familiar.
I agree that if you are not using any specific Commission methods, the cast is unnecessary.