iGET

C# Programming - MCQ Practice Questions

C# (.NET) MCQs — OOP, collections, LINQ & exception handling.

290 questions | 100% Free

Q.1Hard

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();

Q.2Hard

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();

Q.3Hard

What will happen if you try to override a non-virtual method?

Q.4Hard

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();

Q.5Hard

In C#, what happens when you apply the 'static' modifier to a method inside an interface (C# 11+)?

Q.6Hard

In C# 10, what does the 'file' access modifier allow?

Q.7Hard

Which feature in C# 8+ allows you to provide default implementation in an interface?

Q.8Hard

In C# 12, what feature allows creating parameterless struct constructors with field initializers?

Q.9Hard

What is the correct way to implement the Dispose pattern in C# for resource cleanup?

Q.10Hard

A company develops a payment system using multiple payment methods (Credit Card, UPI, Wallet). Which OOP principle best applies here?

Q.11Hard

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?

Q.12Hard

In C# 10+, what is the purpose of the 'file-scoped type' modifier?

Q.13Hard

A developer needs to ensure that a method in a derived class cannot be overridden further. Which keyword should be used?

Q.14Hard

In C#, when implementing IDisposable pattern, what should a derived class do if the base class also implements it?

Q.15Hard

What is covariance in C# generics and interfaces?

Q.16Hard

A logging system needs to handle multiple logger types (File, Database, Console) interchangeably. Which design pattern combined with polymorphism best suits this?

Q.17Hard

What will happen if you try to override a non-virtual method in a derived class in C#?

Q.18Hard

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?

Q.19Hard

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?

Q.20Hard

A gaming application needs to implement different weapons (Sword, Gun, Bow) with different attack methods. Which approach is most maintainable?