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
Implementing Abstract class In C#
Vijayaragavan S
Aug 24
2016
Code
813
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
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#