Which access modifier allows a member to be accessed only within the same assembly?
Answer: B
'internal' access modifier restricts member access to the same assembly only. This is useful for creating assembly-wide internal APIs.
Q.122Hard
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.123Medium
What will be the behavior if a base class method is not marked as 'virtual' and a derived class attempts to override it?
Answer: A
If you override a non-virtual method, C# will hide it and show a compiler warning. Use 'new' keyword to suppress the warning and explicitly hide the base method.
Q.124Medium
Which statement about record types in C# 9+ is correct?
Answer: B
Records (C# 9+) are designed for immutable data with positional parameters, automatic value-based equality, and ToString() implementation.
Q.125Easy
What is the output of using 'nameof()' operator on a property in C#?
Answer: B
'nameof()' operator (C# 6+) returns the name of a variable, type, or member as a string literal, useful for logging and validation.
Advertisement
Q.126Medium
In C#, what is the correct way to implement explicit interface implementation?
Answer: B
Explicit interface implementation is always private by convention and accessed through interface reference only, not through class instance directly.
Q.127Hard
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.128Easy
What happens when you mark a class with the 'sealed' modifier?
Answer: B
'sealed' keyword prevents a class from being inherited. This is useful for security and performance optimization when you want to prevent further derivation.
Q.129Medium
In C#, what is the relationship between composition and inheritance in OOP design?
Answer: B
Composition (HAS-A) and Inheritance (IS-A) serve different purposes. Composition is more flexible and often preferred over inheritance to avoid tight coupling.
Q.130Easy
What does the 'base' keyword do in a derived class method in C#?
Answer: B
'base' keyword is used to access base class members, particularly useful in constructors to call base class constructors or override base methods.
Q.131Easy
Which of the following demonstrates proper encapsulation in C#?
Answer: B
Proper encapsulation uses private fields with public properties, providing controlled access and allowing for future validation logic.
Q.132Hard
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.133Hard
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.134Easy
What is the output behavior of ToString() method when not overridden in a custom class?
Answer: B
Default ToString() (inherited from object) returns the fully qualified namespace and class name. Custom implementations are recommended for meaningful string representation.
Q.135Medium
In C# 11, which feature enables you to define constraints on generic type parameters at compile-time?
Answer: A
'where' clause in generic types constrains type parameters (e.g., where T : class, where T : IComparable). C# 11 added 'allows ref struct' constraint.
Q.136Easy
In C#, which access modifier allows a member to be accessed only within the same class?
Answer: A
The 'private' access modifier restricts access to members within the same class only. It is the most restrictive access level in C#.
Q.137Easy
What is the primary purpose of using interfaces in C#?
Answer: B
Interfaces define a contract that classes must implement, ensuring consistent method signatures across different implementations. They enable polymorphism and loose coupling.
Q.138Easy
In C# inheritance, which keyword allows accessing members of the parent class?
Answer: B
The 'base' keyword is used to access members (properties, methods) of the parent class from within derived class methods, particularly in constructors and method overriding.
Q.139Medium
What does the 'virtual' keyword enable in C#?
Answer: B
The 'virtual' keyword marks a method in the base class as overridable. Derived classes can use 'override' to provide their own implementation.
Q.140Medium
Consider a BankAccount class with private balance field. How should external classes access this field safely?
Answer: B
Properties with accessors (get/set) follow encapsulation principles, allowing controlled access while maintaining data validation logic within the property.