Difficulty: Easy
Correct Answer: Correct — classes can inherit only a single class, though they can implement multiple interfaces.
Explanation:
Introduction / Context:
The question checks C#.NET inheritance capabilities. Unlike C++, C# does not allow multiple inheritance of classes; instead, C# offers multiple interface implementation to achieve polymorphism without the diamond problem complexities found in multiple class inheritance.
Given Data / Assumptions:
Concept / Approach:
In C#, a class declaration uses a single base class followed by zero or more interfaces, for example: class MyType : BaseType, IFoo, IBar { } Only one class can appear directly after the colon. The language disallows more than one class there, enforcing single inheritance. This model simplifies method resolution and runtime semantics while still allowing broad polymorphism through interfaces.
Step-by-Step Solution:
Verification / Alternative check:
Attempting to compile a class with two base classes triggers a compiler error. Replacing the second class with an interface resolves the error immediately.
Why Other Options Are Wrong:
Common Pitfalls:
Confusing multiple interface implementation with multiple class inheritance; assuming partial classes or composition are forms of inheritance; or mixing C++ capabilities with C# limitations.
Final Answer:
Correct — classes can inherit only a single class, though they can implement multiple interfaces.
Discussion & Comments