Home Subjects C# Programming OOP in C#

C# Programming
OOP in C#

C# and .NET for campus placement

51 Q 4 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 51–51 of 51
Topics in C# Programming
Q.51 Medium OOP in C#
What will be the output of the following code?
class A { public virtual void Show() { Console.WriteLine("A"); } }
class B : A { public override void Show() { Console.WriteLine("B"); } }
A obj = new B();
obj.Show();
A A
B B
C Compilation Error
D Runtime Error
Correct Answer:  B. B
EXPLANATION

Due to polymorphism, the overridden method in class B is called, not the virtual method in class A. Output is 'B'.

Test
IGET
IGET AI
Online · Exam prep assistant
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips