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
Accessing Base Class Member In Masked Derived Class in C#
Rajan Singh
Sep 19
2015
Code
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 {
public
byte
second {
set
;
get
;
}
public
void
SetTime(
byte
hour,
byte
minute,
byte
second) {
SetTime(hour, minute);
this
.second = second;
}
new
public
void
DisplayTime() {
base
.DisplayTime();
Console.Write(
":"
+ 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
Accessing Base Class
Derived Class
C#