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
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Maha
NA
0
326.2k
new
Sep 2 2012 8:39 AM
This program is given in the following website (http://www.dotnetperls.com/new-modifier) to demonstrate the function of "new" keyword. But in my view this is not a good example to demonstrate because without "new" keyword program is producing same output. Whether it is possible to alter the program so that it will demonstrate the function of "new"?
using System;
class A
{
public void Y()
{
Console.WriteLine("A.Y");
}
}
class B : A
{
public
new
void Y() //without "new" program is producing same output
{
// This method HIDES A.Y.
// It is only called through the B type reference.
Console.WriteLine("B.Y");
}
}
class Program
{
static void Main()
{
A ref1 = new A(); // Different new
A ref2 = new B();
B ref3 = new B();
ref1.Y();
ref2.Y();
ref3.Y();
Console.ReadKey();
}
}
/*
A.Y
A.Y
B.Y
*/
Reply
Answers (
9
)
c#
How to Program TIMER in C#