C# Programming - MCQ Practice Questions
C# (.NET) MCQs — OOP, collections, LINQ & exception handling.
290 questions | 100% Free
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?
A student management system implements IComparable<Student> to sort students. Which method must be implemented?
What happens when a derived class constructor does not explicitly call the base class constructor in C#?
In a company payroll system, Employee is the base class with CalculateSalary() as virtual method. Manager and Intern classes override it differently. Why is this design preferred?
Which statement about abstract classes in C# is INCORRECT?
What is the output of the following C# code? class Base { public virtual void Display() { Console.WriteLine("Base"); } } class Derived : Base { public override void Display() { Console.WriteLine("Derived"); } } Base obj = new Derived(); obj.Display();
Which keyword in C# is used to prevent a class from being inherited?
What will be the result of the following C# code? class Animal { } class Dog : Animal { } Dog dog = new Animal(); // Line 1
Which of the following correctly demonstrates composition in C#?
In a banking application, you need to create a base class that cannot be instantiated but defines common properties for SavingsAccount and CheckingAccount. Which should you use?
In a logistics system, both Truck and Bicycle need to calculate delivery cost. Instead of duplicating code, you decide to use an interface. What advantage does this provide?
In a real-time inventory management system, a Product class needs to track stock levels that should not be modified directly from outside the class. Which OOP principle should be applied here, and how?
Which method removes all elements from a collection in C#?
What is the time complexity of accessing an element by index in a List<T>?
Which collection maintains insertion order but uses a hash table for faster lookups?
What happens when you try to access an index beyond the Count in a List<T>?