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
Simple Program of Inheritance in C#
Favas CM
Jul 03
2015
Code
1.3
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
Use Inheritance Create 3 classes, first Parrots, second Kiwis and third Mousebird. After then create a function to print details about birdsdetails1. colour2. weight3. length4. height create objects of the three classes and save it in a array then retrieve the object and print details.
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.Threading.Tasks;
namespace
UseInheritanceParrotKiwisMousebird {
public
class
parrots {
int
weight, length, height;
string
colour;
public
void
details(
string
colour,
int
weight,
int
length,
int
height) {
this
.colour = colour;
this
.weight = weight;
this
.length = length;
this
.height = height;
Console.WriteLine(
"\ncolour : "
+ colour);
Console.WriteLine(
"weight : "
+ weight +
" gm"
);
Console.WriteLine(
"length : "
+ length +
" cm"
);
Console.WriteLine(
"height : "
+ height +
" cm"
);
}
}
public
class
kiwi: parrots {}
public
class
mousebird: kiwi {}
class
Program {
static
void
Main(
string
[] args) {
Console.WriteLine(
"PARROTS"
);
parrots pr =
new
parrots();
pr.details(
"red"
, 200, 8, 4);
Console.WriteLine(
"\n\nKIWI"
);
kiwi kw =
new
kiwi();
kw.details(
"yellow"
, 230, 10, 8);
Console.WriteLine(
"\n\nMOUSEBIRD"
);
mousebird mb =
new
mousebird();
mb.details(
"blue"
, 250, 14, 8);
Console.ReadLine();
}
}
}
Output
PARROTS
colour :red
weight :200 gm
length :8 cm
height :4 cm
KIWI
colour : yellow
weight : 230 gm
length : 10 cm
height : 8 cm
MOUSEBIRD
colour : blue
weight : 250 gm
length : 14 cm
height : 8cm
C#
Program of Inheritance