Abstract Class

Abstract Methods--> A method without Method Body is known as abstract method. It contains only declaration of the method. If we want to define an abstract method we need to use abstract modifier on that method.

Abstract Function--> A function which contains only Declaration/signature and doesn't contain Implementation/Body/Definition is known as Abstract function. To make any function as abstract use abstract keyword. An abstract function should be terminated. Overridding of an abstract function is compulsory.

Abstract Class--> A class which contains one or more abstract function is known as an abstract class.To make any Class as abstract use abstract keyword. It's Compulsory to create/ derive a new class from an abstract class in order to provide functionality to its abstract functions.

An abstract class can contain Non-abstract functions. An abstract class can contain all members of a class. By default abstract class functions are not treated as public and abstract.

Program for abstract class
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. namespace Abstract   
  6. {  
  7.     abstract class Employee  
  8.     {  
  9.         protected int EmpId, EAge;  
  10.         protected string EName, EAddress;  
  11.         public abstract void GetEmpData();  
  12.         public virtual void DisplayEmpData()  
  13.         {  
  14.             Console.Write("Enter Employee Details");  
  15.             this.EmpId = Convert.ToInt32(Console.ReadLine());  
  16.             this.EName = Console.ReadLine();  
  17.             this.EAddress = Console.ReadLine();  
  18.             this.EAge = Convert.ToInt32(Console.ReadLine());  
  19.         }  
  20.         public virtual void DispalyEmpData()   
  21.         {  
  22.             Console.WriteLine("Employee Id is :-" + this.EmpId);  
  23.             Console.WriteLine("Employee Name is :-" + this.EName);  
  24.             Console.WriteLine("Employee Address is :-" + this.EAddress);  
  25.             Console.WriteLine("Employee Age is :-" + this.EAge);  
  26.         }  
  27.     }  
  28.     class Manager: Employee  
  29.     {  
  30.         double Bonus, CA;  
  31.         public override void GetEmpData()  
  32.         {  
  33.             Console.Write("Enter Managers Details :-");  
  34.             EmpId = Convert.ToInt32(Console.ReadLine());  
  35.             EName = Console.ReadLine();  
  36.             Bonus = Convert.ToDouble(Console.ReadLine());  
  37.             CA = Convert.ToDouble(Console.ReadLine());  
  38.         }  
  39.         public override void DispalyEmpData() {  
  40.             Console.WriteLine("Manager Id is" + EmpId);  
  41.             Console.WriteLine("Manager Name is" + EName);  
  42.             Console.WriteLine("Manager Bonus is" + Bonus);  
  43.             Console.WriteLine("Manager CA is" + CA);  
  44.         }  
  45.     }  
  46.     class Abstract {  
  47.         static void Main(string[] args) {  
  48.             Manager Obj1 = new Manager();  
  49.             Obj1.GetEmpData();  
  50.             Obj1.DispalyEmpData();  
  51.             Console.ReadLine();  
  52.         }  
  53.     }  
  54. }  
output for this program is-

Enter manager Detail is-- 10
ravi
15000
25000
Manager Id is:- 10
Manager Name is:- ravi
Manager Bonus is:- 15000
Manager CA is:- 25000