C# Programming - MCQ Practice Questions
C# (.NET) MCQs — OOP, collections, LINQ & exception handling.
290 questions | 100% Free
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();
An abstract class Shape has an abstract method CalculateArea(). Which statement is true?
In C#, what is the difference between 'is' and 'as' operators?
In C# 13+ (projected features), nullable reference types help prevent which type of error?
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();
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?
What is the difference between a class and a struct in C#?
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;
An application needs to define behavior that multiple unrelated classes must follow. Which feature should be used?
A developer implements IComparable interface in a Student class. What must the class implement?
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();
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?
A payment processing system implements multiple interfaces: IPayment, IRefundable, IAuditTrail. A PaymentProcessor class must implement all three. Which statement is true?
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?
What is the difference between 'sealed' and 'abstract' keywords in C#?
A vehicle management system requires different vehicle types (Car, Bike, Truck) to calculate toll fees differently. Which feature should be used?
Which of the following statements about virtual methods in C# is TRUE?
A restaurant ordering system needs to ensure each order has a unique ID generated automatically. Which design pattern and feature should be used?
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();
In an inventory management system, a Product class has a Price property. Which approach best ensures price cannot be negative?