Home Subjects C# Programming OOP in C#

C# Programming
OOP in C#

C# and .NET for campus placement

51 Q 4 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 11–20 of 51
Topics in C# Programming
Q.11 Medium OOP in C#
A student management system implements IComparable to sort students. Which method must be implemented?
A GetHashCode()
B CompareTo(Student other)
C Equals(object obj)
D ToString()
Correct Answer:  B. CompareTo(Student other)
EXPLANATION

IComparable<T> interface requires implementation of CompareTo method to define comparison logic between objects of the same type.

Test
Q.12 Medium OOP in C#
In an inventory management system, a Product class has a Price property. Which approach best ensures price cannot be negative?
A Make Price public
B Use private backing field with property validation in setter
C Make Price abstract
D Use static Price
Correct Answer:  B. Use private backing field with property validation in setter
EXPLANATION

Properties with private backing fields allow validation in setters, ensuring data integrity by preventing invalid values like negative prices.

Test
Q.13 Medium OOP in C#
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();
A Some sound
B Bark
C Compilation error
D Runtime error
Correct Answer:  B. Bark
EXPLANATION

Due to polymorphism, the overridden method in Dog class is called at runtime, printing 'Bark' even though the reference type is Animal.

Test
Q.14 Medium OOP in C#
A restaurant ordering system needs to ensure each order has a unique ID generated automatically. Which design pattern and feature should be used?
A Static variable in Order class
B Public variable in Order class
C Protected variable with inheritance
D Interface implementation
Correct Answer:  A. Static variable in Order class
EXPLANATION

Static variables are shared across all instances and can be used to generate unique IDs automatically without modifying external data.

Test
Q.15 Medium OOP in C#
Which of the following statements about virtual methods in C# is TRUE?
A Virtual methods cannot be overridden in derived classes
B Virtual methods allow derived classes to override the base implementation
C Virtual methods are automatically static
D Virtual methods must be abstract
Correct Answer:  B. Virtual methods allow derived classes to override the base implementation
EXPLANATION

Virtual methods are designed to be overridden by derived classes, enabling polymorphic behavior and runtime method resolution.

Test
Q.16 Medium OOP in C#
A vehicle management system requires different vehicle types (Car, Bike, Truck) to calculate toll fees differently. Which feature should be used?
A Method Overloading
B Method Overriding
C Polymorphism through inheritance
D Encapsulation
Correct Answer:  C. Polymorphism through inheritance
EXPLANATION

Polymorphism through inheritance allows each vehicle type to override the toll calculation method with its own implementation, enabling different behavior for each type.

Test
Q.17 Medium OOP in C#
What is the difference between 'sealed' and 'abstract' keywords in C#?
A sealed prevents inheritance; abstract requires inheritance
B abstract prevents instantiation; sealed allows instantiation
C Both prevent instantiation
D sealed creates static members; abstract creates virtual members
Correct Answer:  A. sealed prevents inheritance; abstract requires inheritance
EXPLANATION

sealed prevents a class from being inherited, while abstract requires derived classes to implement its abstract members. They serve opposite purposes.

Test
Q.18 Medium OOP in C#
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?
A Polymorphism
B Inheritance
C Encapsulation
D Abstraction
Correct Answer:  B. Inheritance
EXPLANATION

Inheritance allows creating a base class (LibraryItem) with common properties, and derived classes can inherit these properties, reducing code duplication.

Test
Q.19 Medium OOP in C#
A payment processing system implements multiple interfaces: IPayment, IRefundable, IAuditTrail. A PaymentProcessor class must implement all three. Which statement is true?
A C# does not support multiple interface implementation
B Only one interface can be implemented at a time
C PaymentProcessor can implement all three interfaces and must implement all their methods
D Multiple interface implementation requires abstract classes
Correct Answer:  C. PaymentProcessor can implement all three interfaces and must implement all their methods
EXPLANATION

C# supports multiple interface implementation. A class can implement multiple interfaces separated by commas, and must implement all abstract members of each interface.

Test
Q.20 Medium OOP in 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 Use an Interface
B Use a Sealed Class with virtual methods
C Use an Abstract Class
D Use a Static Class
Correct Answer:  C. Use an Abstract Class
EXPLANATION

Abstract classes can have both concrete (implemented) and abstract (unimplemented) methods. They cannot be instantiated directly but can be inherited. This perfectly fits the requirement.

Test
IGET
IGET AI
Online · Exam prep assistant
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips