Can we have the method in drived class with the same name
which is there in base class?

Answer Posted / brijender p rana

It is possible to hide the base class method with the
derived class without using Virtual in base class and
Override keyword in subclass.there are some condition where
we have to redefine any method in derived class same name
in base class now question arise how can we hide the method
anwer is simple and logical we use the modifier NEW which
tell the compiler that derived class method "hides the base
class method. There are some example:
Class baseclass
{
Public void display()
{
console.writeline("base method");
}
}
class derived : baseclass
{
public new void display()
{
console.writeline("dervied mthod");
}
}
class test
{
public static void main()
{
derived d=new derivedclass();
d.display();
}
}

Is This Answer Correct ?    5 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Give an example of a ctype.

746


Why do we need abstract class?

641


what is the difference between a struct and a class in c#?

777


What is the lock statement in c#?

726


How long can loop recorders stay in?

869


What is Co- and Contra-Variance in C#?

719


Explain types of comment in c# with examples

676


Explain about c# language.

795


What is main thread in c#?

682


What is gridview c#?

664


What is generic in c#?

620


What is semaphore in c#?

685


Describe an abstract class?

726


Why do we need singleton class in c#?

711


What is part of a method signature in c#?

648