iGET

C# Programming - MCQ Practice Questions

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

290 questions | 100% Free

Q.141Medium

A developer creates a class Library and another class Book. The Library class contains multiple Book objects. What is this relationship called?

Q.142Medium

In C# 9+, which feature allows you to create immutable reference types?

Q.143Medium

What is the output of the following code? class Animal { public virtual void Sound() { Console.WriteLine("Generic Sound"); } } class Dog : Animal { public override void Sound() { Console.WriteLine("Bark"); } } Dog dog = new Dog(); dog.Sound();

Q.144Medium

An abstract class Shape has an abstract method CalculateArea(). Which statement is true?

Q.145Medium

In C#, what is the difference between 'is' and 'as' operators?

Q.146Hard

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

Q.147Hard

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.148Hard

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

Q.149Hard

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

Q.150Hard

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

Q.151Hard

What is covariance in C# generics and interfaces?

Q.152Hard

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

Q.153Medium

In C# 13+ (projected features), nullable reference types help prevent which type of error?

Q.154Easy

Which of the following best describes encapsulation in C#?

Q.155Medium

What is the output of the following C# code? public class Base { public virtual void Display() { Console.WriteLine("Base"); } } public class Derived : Base { public override void Display() { Console.WriteLine("Derived"); } } Base obj = new Derived(); obj.Display();

Q.156Medium

A developer creates an abstract class Account with an abstract method CalculateInterest(). Two derived classes SavingsAccount and CurrentAccount implement this method differently. This scenario best demonstrates which OOP principle?

Q.157Medium

What is the difference between a class and a struct in C#?

Q.158Medium

In C#, what will be the output of the following code? class Test { public Test() { Console.WriteLine("Constructor"); } ~Test() { Console.WriteLine("Destructor"); } } Test t = new Test(); t = null;

Q.159Medium

An application needs to define behavior that multiple unrelated classes must follow. Which feature should be used?

Q.160Easy

What is the purpose of the 'base' keyword in C#?