O'Reilly logo

Pro C# 2010 and the .NET 4 Platform, Fifth Edition by Andrew Troelsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

6.5. The Third Pillar of OOP: C#'s Polymorphic Support

Recall that the Employee base class defined a method named GiveBonus(), which was originally implemented as follows:

public partial class Employee
{
  public void GiveBonus(float amount)
  {
    currPay += amount;
  }
...
}

Because this method has been defined with the public keyword, you can now give bonuses to salespeople and managers (as well as part-time salespeople):

static void Main(string[] args) { Console.WriteLine("***** The Employee Class Hierarchy *****\n"); // Give each employee a bonus? Manager chucky = new Manager("Chucky", 50, 92, 100000, "333-23-2322", 9000); chucky.GiveBonus(300); chucky.DisplayStats(); Console.WriteLine(); SalesPerson fran = new SalesPerson("Fran", 43, 93, 3000, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required