iGET

C# Programming - MCQ Practice Questions

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

290 questions | 100% Free

Q.21Medium

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.22Medium

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

Q.23Medium

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

Q.24Medium

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

Q.25Medium

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.26Medium

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.27Medium

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

Q.28Medium

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.29Medium

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

Q.30Medium

A developer implements IComparable interface in a Student class. What must the class implement?

Q.31Medium

What is the correct order of constructor execution in multilevel inheritance? class A { public A() { Console.WriteLine("A"); } } class B : A { public B() { Console.WriteLine("B"); } } class C : B { public C() { Console.WriteLine("C"); } } new C();

Q.32Medium

An e-commerce system needs to ensure that a Product class cannot be instantiated directly but can be inherited. Additionally, it must define some concrete methods and some abstract methods. Which approach is best?

Q.33Medium

A payment processing system implements multiple interfaces: IPayment, IRefundable, IAuditTrail. A PaymentProcessor class must implement all three. Which statement is true?

Q.34Medium

In a library management system, multiple types of items (Book, Magazine, DVD) share common properties like ID and Title. Which OOP principle should be applied here?

Q.35Medium

What is the difference between 'sealed' and 'abstract' keywords in C#?

Q.36Medium

A vehicle management system requires different vehicle types (Car, Bike, Truck) to calculate toll fees differently. Which feature should be used?

Q.37Medium

Which of the following statements about virtual methods in C# is TRUE?

Q.38Medium

A restaurant ordering system needs to ensure each order has a unique ID generated automatically. Which design pattern and feature should be used?

Q.39Medium

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

Q.40Medium

In an inventory management system, a Product class has a Price property. Which approach best ensures price cannot be negative?