In C# 10, what does the 'file' access modifier allow?
Answer: B
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.
Q.22Hard
Which feature in C# 8+ allows you to provide default implementation in an interface?
Answer: B
C# 8 introduced default interface implementations, allowing interfaces to have method bodies that implementing classes can inherit or override.
Q.23Hard
In C# 12, what feature allows creating parameterless struct constructors with field initializers?
Answer: B
C# 12 allows field initializers directly in struct declarations, enabling parameterless constructors with initialized default values.
Q.24Hard
What is the correct way to implement the Dispose pattern in C# for resource cleanup?
Answer: A
The proper Dispose pattern implements IDisposable and uses a finalizer/destructor as a safety net, following the recommended pattern in C#.
Q.25Hard
A company develops a payment system using multiple payment methods (Credit Card, UPI, Wallet). Which OOP principle best applies here?
Answer: B
Creating an IPayment interface with different payment classes implementing it demonstrates polymorphism, allowing the system to handle various payment methods uniformly.
Advertisement
Q.26Hard
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?
Answer: C
Due to method overriding and polymorphism, C's Display() executes if overridden. Otherwise, the most derived available implementation in the inheritance chain executes.
Q.27Hard
In C# 10+, what is the purpose of the 'file-scoped type' modifier?
Answer: A
The 'file' access modifier (C# 11+) restricts type visibility to the file it's declared in, improving encapsulation at the file level.
Q.28Hard
A developer needs to ensure that a method in a derived class cannot be overridden further. Which keyword should be used?
Answer: B
'sealed override' prevents further overriding of an already overridden virtual method in derived-from-derived classes.
Q.29Hard
In C#, when implementing IDisposable pattern, what should a derived class do if the base class also implements it?
Answer: B
Derived classes must call base.Dispose() to ensure proper cleanup of base class resources, following the disposable pattern correctly.
Q.30Hard
What is covariance in C# generics and interfaces?
Answer: B
Covariance (using 'out' keyword) allows a more derived type to be returned where a base type is expected, improving type safety and flexibility.
Q.31Hard
A logging system needs to handle multiple logger types (File, Database, Console) interchangeably. Which design pattern combined with polymorphism best suits this?
Answer: B
Strategy pattern defines a family of algorithms (logger types) and makes them interchangeable through interface polymorphism, allowing runtime selection.
Q.32Hard
What will happen if you try to override a non-virtual method in a derived class in C#?
Answer: B
In C#, if you attempt to override a non-virtual method without using 'new' keyword, the compiler issues a warning but the method is hidden (not overridden). Using 'new' keyword explicitly hides the base method.
Q.33Hard
A banking application uses inheritance where Account is the parent class and SavingsAccount, CurrentAccount are derived classes. Each has different withdrawal rules. Which design principle is being followed?
Answer: B
Open/Closed Principle states that classes should be open for extension (SavingsAccount, CurrentAccount extend Account) but closed for modification (Account class rules remain unchanged). This is a classic example of OCP.
Q.34Hard
In a hospital management system, Doctor and Nurse classes need to perform a common Logout() operation but have different Login() procedures. What is the best OOP approach?
Answer: A
A base class with virtual Logout() allows common implementation, while abstract Login() forces derived classes to provide their own implementation. This combines code reuse with flexibility.
Q.35Hard
A web application needs to store a user preference that persists across multiple browser sessions. Which state management technique is most appropriate?
Answer: A
For persistent data across multiple sessions, database storage is the best approach. Session State is temporary and Application State is server-wide.
Q.36Hard
What is the correct order of Page Lifecycle events in ASP.NET Web Forms?
Answer: A
ASP.NET Web Forms lifecycle: Init → Load → Event Handling (ViewState restored) → Render → Unload.
Q.37Hard
An e-commerce application needs to handle concurrent user requests efficiently. Which ASP.NET Core feature is most suitable?
Answer: A
Async/Await enables non-blocking I/O operations, allowing ASP.NET Core to handle more concurrent requests efficiently.
Q.38Hard
In ASP.NET Core, which method is used to register services in the dependency injection container?
Answer: A
AddScoped, AddSingleton, and AddTransient are methods to register services with different lifetimes in ASP.NET Core DI.
Q.39Hard
A developer needs to create a RESTful API that returns JSON data. Which ASP.NET approach is most suitable?
Answer: A
ASP.NET Core Web API with [ApiController] attribute is the modern approach for building RESTful APIs that return JSON.
Q.40Hard
A gaming application needs to implement different weapons (Sword, Gun, Bow) with different attack methods. Which approach is most maintainable?
Answer: A
Inheritance and polymorphism provide better maintainability, scalability, and follow SOLID principles compared to conditional logic.