Home Subjects C# Programming OOP in C#

C# Programming
OOP in C#

C# and .NET for campus placement

25 Q 4 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 11–20 of 25
Topics in C# Programming
Q.11 Hard OOP in C#
What is covariance in C# generics and interfaces?
A Same type variance for all generic parameters
B Allowing derived types where base types are expected in return types
C Preventing type variance entirely
D Using 'in' keyword for contravariance only
Correct Answer:  B. Allowing derived types where base types are expected in return types
EXPLANATION

Covariance (using 'out' keyword) allows a more derived type to be returned where a base type is expected, improving type safety and flexibility.

Test
Q.12 Hard OOP in C#
In C#, when implementing IDisposable pattern, what should a derived class do if the base class also implements it?
A Ignore the base implementation
B Call base.Dispose() within its Dispose() override
C Reimplement IDisposable completely
D Use only static Dispose methods
Correct Answer:  B. Call base.Dispose() within its Dispose() override
EXPLANATION

Derived classes must call base.Dispose() to ensure proper cleanup of base class resources, following the disposable pattern correctly.

Test
Q.13 Hard OOP in C#
A developer needs to ensure that a method in a derived class cannot be overridden further. Which keyword should be used?
A virtual sealed
B sealed override
C abstract sealed
D override private
Correct Answer:  B. sealed override
EXPLANATION

'sealed override' prevents further overriding of an already overridden virtual method in derived-from-derived classes.

Test
Q.14 Hard OOP in C#
In C# 10+, what is the purpose of the 'file-scoped type' modifier?
A To restrict type visibility to the current file only
B To improve code execution speed
C To enable file compression
D To manage file permissions
Correct Answer:  A. To restrict type visibility to the current file only
EXPLANATION

The 'file' access modifier (C# 11+) restricts type visibility to the file it's declared in, improving encapsulation at the file level.

Test
Q.15 Hard OOP in C#
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?
A A's Display()
B B's Display()
C C's Display() if overridden, otherwise B's
D All three methods sequentially
Correct Answer:  C. C's Display() if overridden, otherwise B's
EXPLANATION

Due to method overriding and polymorphism, C's Display() executes if overridden. Otherwise, the most derived available implementation in the inheritance chain executes.

Test
Q.16 Hard OOP in C#
A company develops a payment system using multiple payment methods (Credit Card, UPI, Wallet). Which OOP principle best applies here?
A Encapsulation only
B Polymorphism through interface implementation
C Inheritance only
D Abstraction only
Correct Answer:  B. Polymorphism through interface implementation
EXPLANATION

Creating an IPayment interface with different payment classes implementing it demonstrates polymorphism, allowing the system to handle various payment methods uniformly.

Test
Q.17 Hard OOP in C#
What is the correct way to implement the Dispose pattern in C# for resource cleanup?
A Implement IDisposable with Dispose method and destructor
B Only implement a destructor
C Only implement the IDisposable interface
D Use only finalizers without IDisposable
Correct Answer:  A. Implement IDisposable with Dispose method and destructor
EXPLANATION

The proper Dispose pattern implements IDisposable and uses a finalizer/destructor as a safety net, following the recommended pattern in C#.

Test
Q.18 Hard OOP in C#
In C# 12, what feature allows creating parameterless struct constructors with field initializers?
A Struct initialization expressions
B Field initializers in structs
C Explicit struct constructors
D Default struct methods
Correct Answer:  B. Field initializers in structs
EXPLANATION

C# 12 allows field initializers directly in struct declarations, enabling parameterless constructors with initialized default values.

Test
Q.19 Hard OOP in C#
Which feature in C# 8+ allows you to provide default implementation in an interface?
A Virtual methods
B Default interface implementations
C Abstract methods
D Static constructors
Correct Answer:  B. Default interface implementations
EXPLANATION

C# 8 introduced default interface implementations, allowing interfaces to have method bodies that implementing classes can inherit or override.

Test
Q.20 Hard OOP in C#
In C# 10, what does the 'file' access modifier allow?
A Access members across different files in the same project
B Restricts type visibility to the current file only
C Allows file-level access from external assemblies
D Enables file streaming operations for the type
Correct Answer:  B. Restricts type visibility to the current file only
EXPLANATION

The 'file' scoped type modifier (C# 11) restricts a type to be visible only within the file it's declared in, preventing accidental public API expansion.

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