Overriding Inherited Behavior

A derived class can override behavior inherited from the base class, which allows a derived type to apply more specific behavior. The Pay method of the Employee class is overridden in CommissionedEmployee to consider commissions when calculating a paycheck. In the SalariedEmployee class, the Pay method is overridden to calculate pay by prorating annual income. Methods, properties, indexers, and events can be overridden. Fields and static members cannot be overridden. However, they can be hidden in the derived class.

Can a child override a member of the parent at any time? With human beings, most parents hope that their children inherit and observe their recommended behavior. However, the behavior of the parent is merely ...

Get Programming Microsoft® Visual C#® 2008: The Language now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.