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

What are the types of comment in c# with examples?

471


Can you specify nested classes as partial classes?

494


What is wpf c#?

481


What is predicate c#?

534


What is difference between class and interface in c#?

446






What is event sourcing in c#?

492


What is sqladapter c#?

520


What is jit? What are the different types of jit?

560


What is get set in c#?

548


Does main have to be static c#?

478


Can namespace contain the private class?

482


What do you mean by winforms in c#?

494


What is local function?

506


What are extensions in c#?

528


Name the two classes are required for implementing a windows service?

536