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
- Overriding of an abstract function is compulsory
Abstract
class:
- A class which contains one (or) more direct functions is known as an abstract class
- To make any class as abstract use abstract keyword
- An abstract class can’t be instantiated directly
- 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
Example
:-
Class Diagram:-
using System;
using
System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CAAbstract
{
abstract class ClsEmployee
{
protected
int EmpId, EAge;
protected
string EName, EAddress;
public
abstract void
GetEmpData();
public
virtual void
DisplayEmpData()
{
Console.WriteLine("Employee Id is :-
" + this.EmpId);
Console.WriteLine("Employee Name is :-
" + this.EName);
Console.WriteLine("Employee Address is :-
" + this.EAddress);
Console.WriteLine("Employee Age is :-
" + this.EAge);
}
}
class ClsManager : ClsEmployee
{
double
Bonus, CA;
public
override void
GetEmpData()
{
Console.Write("Enter Manager Details:- \n");
Console.WriteLine("Enter Manager id");
EmpId = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter Manager Name");
EName = Console.ReadLine();
Console.WriteLine("Enter Manager Bonus");
Bonus = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter Manager CA");
CA = Convert.ToDouble(Console.ReadLine());
}
public
override void
DisplayEmpData()
{
Console.WriteLine("Manager Id is
:- " + EmpId);
Console.WriteLine("Manager Name is
:- " + EName);
Console.WriteLine("Manager Bonus is :- " + Bonus);
Console.WriteLine("Manager CA is
:- " + CA);
}
}
class ClsAbstract
{
static
void Main(string[]
args)
{
ClsManager
Obj1 = new ClsManager();
Obj1.GetEmpData();
Obj1.DisplayEmpData();
Console.Read();
}
}
}
|
Output :-
No comments:
Post a Comment