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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.