abstract class class-name
{
Data Members;
General methods
Abstract Methods;
}
See the sample program to better understand abstract class and method. The following program calculates the net salary of an employee.
//Abstract class
abstract class Demo
{
protected string name;
protected int id;
public void Get(string n , int i)
{
name = n;
id = i;
}
//Defining Abstract methods
public abstract void Set(string des , double sal);
public abstract void Salary();
}
class Salary:Demo
{
string designation;
double netsalary , salary;
//Overriding Abstract methods
public override void Set(string des , double sal)
{
designation = des;
salary = s;
}
public override void Salary()
{
netsalary = salary + salary * 0.25;
}
public void Show()
{
Console.WriteLine("Name:-{0}",name);
Console.WriteLine("ID:-{1}", id);
Console.WriteLine("Designation:-{2}" , designation);
Console.WriteLine("Salary={3}" , salary);
Console.WriteLine("Net Salary={4}" , netsalary);
}
}
class MainClass
{
static void Main(string args[])
{
Salary s = new Salary();
s.Get("Abhisek Panda" , 108);
s.Set("Analyst" , 50000);
s.Salary();
s.Show();
}
}