C# Programming - MCQ Practice Questions
C# (.NET) MCQs — OOP, collections, LINQ & exception handling.
290 questions | 100% Free
What is the output of the following? class A { public void Test() { Console.WriteLine("A"); } } class B : A { public new void Test() { Console.WriteLine("B"); } } A a = new B(); a.Test();
Consider the following code. What will be the output? interface I1 { void Show(); } interface I2 { void Show(); } class C : I1, I2 { public void Show() { Console.WriteLine("C"); } } C obj = new C(); obj.Show();
What will happen if you try to override a non-virtual method?
What is the output of the following code? class Base { public virtual void Method() { Console.WriteLine("Base"); } } class Derived : Base { public override void Method() { base.Method(); Console.WriteLine("Derived"); } } Derived d = new Derived(); d.Method();
In C#, what happens when you apply the 'static' modifier to a method inside an interface (C# 11+)?
In C# 10, what does the 'file' access modifier allow?
Which feature in C# 8+ allows you to provide default implementation in an interface?
In C# 12, what feature allows creating parameterless struct constructors with field initializers?
What is the correct way to implement the Dispose pattern in C# for resource cleanup?
A company develops a payment system using multiple payment methods (Credit Card, UPI, Wallet). Which OOP principle best applies here?
Consider a scenario where class C inherits from B, and B inherits from A. If all three have a method Display(), what does calling Display() on C object invoke?
In C# 10+, what is the purpose of the 'file-scoped type' modifier?
A developer needs to ensure that a method in a derived class cannot be overridden further. Which keyword should be used?
In C#, when implementing IDisposable pattern, what should a derived class do if the base class also implements it?
What is covariance in C# generics and interfaces?
A logging system needs to handle multiple logger types (File, Database, Console) interchangeably. Which design pattern combined with polymorphism best suits this?
What will happen if you try to override a non-virtual method in a derived class in C#?
A banking application uses inheritance where Account is the parent class and SavingsAccount, CurrentAccount are derived classes. Each has different withdrawal rules. Which design principle is being followed?
In a hospital management system, Doctor and Nurse classes need to perform a common Logout() operation but have different Login() procedures. What is the best OOP approach?
A gaming application needs to implement different weapons (Sword, Gun, Bow) with different attack methods. Which approach is most maintainable?