Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
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
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Implementing Abstract class In C#
WhatsApp
Vijayaragavan S
Aug 24
2016
853
0
0
using
System;
abstract
class
person {
protected
string
fname;
protected
string
lname;
public
person(
string
fn,
string
ln) {
fname = fn;
lname = ln;
}
public
virtual
void
display() {
Console.WriteLine(
"Person :"
+ fname +
" "
+ lname);
}
}
class
emp: person {
public
ushort
year;
public
emp(
string
fn,
string
ln,
ushort
yr):
base
(fn, ln) {
year = yr;
}
public
override
void
display() {
Console.WriteLine(
"Employee :"
+ fname +
" "
+ lname +
" "
+ year);
}
}
class
worker: person {
public
String company;
public
worker(
string
fn,
string
ln,
string
c):
base
(fn, ln) {
company = c;
}
public
override
void
display() {
Console.WriteLine(
"Worker :"
+ fname +
" "
+ lname +
" "
+ company);
}
}
class
Program {
static
void
Main(
string
[] args) {
Console.WriteLine(
"**ABSTRACT CLASS **"
);
person p2 =
new
emp(
"Vijay"
,
"Senthil"
, 2012);
person p3 =
new
worker(
"Vijay"
,
"Senthil"
,
"C Sharp Corner"
);
p2.display();
p3.display();
Console.ReadKey();
}
}
Abstract class
C#
Up Next
Implementing Abstract class In C#