C#.NET — Interfaces: choose the correct statement.

C# Programming Interfaces Difficulty: Easy
Choose an option
  • A
    All interfaces are derived from the Object class.
  • B
    Interfaces can be inherited (one interface can inherit from another).
  • C
    All interfaces are derived from an Object interface.
  • D
    Interfaces can contain only method declarations, nothing else.
  • E
    Interfaces can contain static data and static methods.

Answer

Correct Answer: Interfaces can be inherited (one interface can inherit from another).

Explanation

Introduction / Context:This question evaluates your grasp of what interfaces are and how they relate to other types in C#.NET. It distinguishes interface inheritance from class inheritance and clarifies what members interfaces may declare.

Given Data / Assumptions:

  • We consider standard C# interface rules used in most exam contexts.

Concept / Approach:An interface can inherit from one or more interfaces, enabling contract composition. Interfaces themselves do not derive from System.Object in the class-inheritance sense (their BaseType in reflection is null). Historically, interfaces contained signatures for methods, properties, indexers, and events. (Modern C# allows additional patterns, but exams typically focus on classic rules.)

Step-by-Step Solution:

Option B — Correct: interface IChild : IParent { … } is valid. Option A — Incorrect: interfaces are not class types and do not “derive” from Object as classes do. Option C — Incorrect: there is no “Object interface.” Option D — Incorrect: interfaces can also declare properties, indexers, and events (signatures). Option E — Incorrect in typical exam scope: traditional interfaces do not contain static data/methods.

Verification / Alternative check:Compile interface I1 { int P { get; } } and interface I2 : I1 { void M(); }. It compiles, proving interface inheritance.

Why Other Options Are Wrong:They either confuse interface inheritance with class inheritance or incorrectly restrict/expand allowed members.

Common Pitfalls:Thinking that all types “inherit” from Object exactly the same way; applying class-only rules to interfaces.

Final Answer:Interfaces can be inherited (one interface can inherit from another).

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