How to use a Abstract classes

Rajesh081725
Posted by Rajesh081725 under C# category on | Points: 40 | Views : 1130
declares an abstract Employee class. You also create a derived class called Manager that provides an implementation of the abstract Show() method defined in the Employee class:


public abstract class Employee
{
protected string name;

public Employee(string name) // constructor
{
this.name = name;
}

public abstract void Show(); // abstract show method
}

public class Manager: Employee
{
public Manager(string name) : base(name) {} // constructor

public override void Show() //override the abstract show method
{
System.Console.WriteLine("Name : " + name);
}
}

class TestEmployeeAndManager
{
static void Main()
{
// Create an instance of Manager and assign it to a Manager reference:
Manager m1 = new Manager("H. Ackerman");
m1.Show();

// Create an instance of Manager and assign it to an Employee reference:
Employee ee1 = new Manager("M. Knott");
ee1.Show(); //call the show method of the Manager class
}
}

Comments or Responses

Login to post response