Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Abstract Class
WhatsApp
Sudeep Chourasia
8y
3
k
0
0
25
Blog
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
Up Next
Class, Inheritance And Abstract Class With Real Time Examples In C#
Ebook Download
View all
LINQ Quick Reference with C#
Read by 44.7k people
Download Now!
Learn
View all
Membership not found