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
Difference between type constructor and instance constructor? What is static constructor, when it will be fired? And what is its use?
What do you mean by stack and heap in c#?
Define acid rule of thumb for transactions in c#.
Can fields inside a class be virtual?
What are the fundamental differences between value types and reference types?
What is the difference between overriding and overloading in systemverilog?
What is sealed class in c#?
How to prevent the error while updating ui control from another thread?
List some of the basic string operation?
What is parsing?
What is console write in c#?
What is the main purpose of xml?
If the interface in c# only contains the declaration of the methods and we need to define those methods in the class, then why we use the interface?
How do you create user defined data types in c#?
What is function c#?