Suppose I had the following code:
Class NormalEmployee
Protected pay As Decimal;
Protected Shared basePay As Decimal = 300D
Protected Overridable Sub UpdatePay()
pay = basePay + .....do something......
End Sub
End Class
Class SeniorNormalEmployee
Inherits Normal Employee
Protected Shared Shadows basePay As Decimal = 500D;
Protected Overrides Sub UpdatePay()
pay = basePay + .....do something different....
End Sub
End Class
Function Main() As Integer
Dim newEmployee As NormalEmployee = New SeniorNormalEmployee()
newEmployee.CalculatePay()
return 0
End Function
I know that due to polymorphism, the CalculatePay() from my base class will be called. My question is: why does CalculatePay() use the basePay from the base class and not the derived class? The object is being stored inside a base class "container", so even though it uses the derived classes version of the method, when it goes to check the basePay shouldn't it look at the base class's version?
Furthermore, is this behavior the same when calling shadowed methods from an overrides method? Is there any way to make a field "Overridable"?
Thanks for any help!