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
What is the difference between virtual method and abstract method?
How to use exception handling in stored procedure?
What is inumerable?
What is #region in c#?
Is 0 an unsigned integer?
What are satellite assemblies?
What is the difference between “out” and “ref” parameters in c#?
Can you see a loop recorder?
What is a verbatim string literal and why do we use it?
What does console writeline do?
I need code to connect ohter systems in the LAN and i want to display my website image over there and i want explain as a admin through phone. So i need code to access other system using C-Sharp. Any one please help me.Please give me the code. Advace thanks.
What are fields in c#?
update data in an xml file which resides in solution itself, using silverlight 4.0
How to find Percentage, name ,College from a resume or document ? How to export these values to other page in C#?
What is dictionary and hashtable in c#?