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
Base Class Inherited Members Masking In Derived Class in C#
Rajan Singh
Sep 19
2015
Code
1.1
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
using
System;
class
Time {
public
byte
hour {
set
;
get
;
}
public
byte
minute {
set
;
get
;
}
public
void
SetTime(
byte
hour,
byte
minute) {
this
.hour = hour;
this
.minute = minute;
}
public
void
DisplayTime() {
Console.Write(hour +
":"
+ minute);
}
}
class
NewTime: Time {
new
public
byte
hour {
get
;
set
;
}
new
public
byte
minute {
get
;
set
;
}
public
byte
second {
set
;
get
;
}
public
void
SetTime(
byte
hour,
byte
minute,
byte
second) {
this
.hour = hour;
this
.minute = minute;
this
.second = second;
}
new
public
void
DisplayTime() {
Console.Write(hour +
":"
+ minute +
":"
+ second);
}
}
class
UsingTime {
static
void
Main(String[] arg) {
Console.WriteLine(
"Base Time Class"
);
Time hmt =
new
Time();
hmt.SetTime(12, 22);
Console.Write(
"Time of HMT: "
);
hmt.DisplayTime();
Console.WriteLine(
"\n\nDerived Time Class"
);
NewTime sonata =
new
NewTime();
Console.Write(
"Time of SONATA: "
);
sonata.SetTime(10, 15, 30);
sonata.DisplayTime();
}
}
Output
Base Time Class:
Time of HMT: 12:22
Derived Time Class
Time of SONATA: 10:15:30
Base Class
Derived Class
C#