C#.NET — Interfaces: pick the single correct statement (clarifying implementation vs inheritance).

Difficulty: Easy

Correct Answer: A class that implements an interface can explicitly implement members of that interface.

Explanation:


Introduction / Context:
This question distinguishes between how interfaces are consumed by classes and how interfaces relate to each other. It also clarifies explicit interface implementation.



Given Data / Assumptions:

  • Classic C# exam scope (interfaces declare contracts; classes/structs implement them).


Concept / Approach:
Explicit interface implementation lets a class provide an implementation that is only accessible through the interface reference (e.g., void IFoo.M() { … }). While multiple classes can implement the same interface, this question requires a single correct choice; we therefore use the statement that is both precise and uniquely framed.



Step-by-Step Solution:

A — Incorrect wording: interfaces inherit from interfaces; they are not “implemented in” one another. B — Although true in general, the question asks for a single best fact; option C is more specific and instructive for exams. C — Correct: explicit implementation syntax is allowed and common for resolving name clashes or hiding members from the class’s public surface. D — False in classic rules: interface members are declarations without bodies. E — False: any concrete class or struct can implement an interface.


Verification / Alternative check:
Write class C : IFoo { void IFoo.M() { } } and call ((IFoo)new C()).M(); — compiles and runs.



Why Other Options Are Wrong:
They misuse terms (implement vs inherit), or incorrectly restrict who can implement, or claim bodies exist in interface methods.



Common Pitfalls:
Mixing up interface-to-interface inheritance with implementation by classes; forgetting explicit implementation exists.



Final Answer:
A class that implements an interface can explicitly implement members of that interface.

More Questions from Interfaces

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion