Method Override in C# OOPS
I know the concepts of method/function override in c#. But my question is when we should use this concept? Could any please explain this with real time scenerio.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Vinitha TPosted Nov 13, 2021, 11:54 AM
When derived class has the same method as in base class, we can use method override.
public class A{
public virtual void do(){
Console.WriteLine("base");
}
}
public class B:A{
public override void do(){
Console.WriteLine("derived");
}
}
public class Demo{
public static void Main(){
B obj=new B();
obj.do();
}
}
OUTPUT:
derived
Raja TPosted Jul 11, 2016, 7:28 AM
Rajeesh MenothPosted Jul 11, 2016, 7:14 AM
Ehsan SajjadPosted Jul 11, 2016, 6:54 AM