TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Abstract Class
Sudeep Chourasia
May 15, 2016
2.9
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
In this blog I explain 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
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
namespace
Abstract
{
abstract
class
Employee
{
protected
int
EmpId, EAge;
protected
string
EName, EAddress;
public
abstract
void
GetEmpData();
public
virtual
void
DisplayEmpData()
{
Console.Write(
"Enter Employee Details"
);
this
.EmpId = Convert.ToInt32(Console.ReadLine());
this
.EName = Console.ReadLine();
this
.EAddress = Console.ReadLine();
this
.EAge = Convert.ToInt32(Console.ReadLine());
}
public
virtual
void
DispalyEmpData()
{
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
Manager: Employee
{
double
Bonus, CA;
public
override
void
GetEmpData()
{
Console.Write(
"Enter Managers Details :-"
);
EmpId = Convert.ToInt32(Console.ReadLine());
EName = Console.ReadLine();
Bonus = Convert.ToDouble(Console.ReadLine());
CA = Convert.ToDouble(Console.ReadLine());
}
public
override
void
DispalyEmpData() {
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
Abstract {
static
void
Main(
string
[] args) {
Manager Obj1 =
new
Manager();
Obj1.GetEmpData();
Obj1.DispalyEmpData();
Console.ReadLine();
}
}
}
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
Abstract class
Next Recommended Reading
Class, Inheritance And Abstract Class With Real Time Examples In C#