Monday, 15 September 2014

vb.net - Using shadowed methods/fields in an overriden method -


Suppose I had the following code:

  class as normalized employee in the form of pay scale; Protected Shared Base on as decimal = 300D Protected Overridwy all updates pay () pay = base pay ... ..... anything ...... and all class senior senior general general employee employee common shareholder protected share Shades pay basses as decimal / 500d; Protected Overrides All Update Pay () Pay = BasePay ..... Something different ... And Sub and Class Function Men (General) Employee Employee Employee Dim New Emporter = New Senior General Staff (new) Employee.CalculatePay ( ) Return 0 and Function  

I know that due to polymorphism, the calculation pay () from my base class will be called. My question is: Why calculate pay () uses base pay from base class and not from derivative class? The object is being deposited inside a base class "container" even if it uses the derived class version of the method, when it goes to check the base pay, then it should not see the base class version ?

In addition, is this behavior similar, when an override method is called shaded methods? Is there any way to make an area "overridive"?

Thanks for any help!

The problem is that using the keyword shadow Variable, when you have used polymorphism in terms of base class and your newEmployee is defined as normalized employee , basepay basis Is one of the class. For more information, check.


No comments:

Post a Comment