Difficulty: Easy
Correct Answer: Declare the class as sealed.
Explanation:
Introduction / Context:
Sometimes an API designer wants to stop consumers from deriving from a class (for safety, simplicity, or design reasons). C# offers a built-in way to accomplish this.
Given Data / Assumptions:
Concept / Approach:
Use the sealed modifier on a class declaration to prevent inheritance: public sealed class MyClass { } Any attempt to derive from MyClass will be a compile-time error.
Step-by-Step Solution:
Verification / Alternative check:
Create a sealed class and try deriving: the compiler reports an error that it cannot derive from sealed type.
Why Other Options Are Wrong:
They are either non-existent modifiers in C# (shadows, suppress) or apply to members (override), not to prevent inheritance at class level.
Common Pitfalls:
Confusing method-level override/new with class-level inheritance control; mixing VB terms (Shadows) with C#.
Final Answer:
Declare the class as sealed.
Derived
object if each int
is 4 bytes (ignore header/alignment)?
Discussion & Comments