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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Raja TRank #685 · 3.5K reputationPosted Jul 11, 2016, 3:28 AM EDT
Vinitha TRank #8,005 · 230 reputationPosted Nov 13, 2021, 6:54 AM EST
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
Ehsan SajjadRank #512 · 4.8K reputationPosted Jul 11, 2016, 2:54 AM EDT
Rajeesh MenothRank #118 · 18.4K reputationPosted Jul 11, 2016, 3:14 AM EDT