C#.NET — Which kinds of types can implement an interface? Consider these candidates: (1) Data (n/a), (2) Class, (3) Enum, (4) Structure, (5) Namespace. Select all that can implement an interface.

Difficulty: Easy

Correct Answer: 2, 4

Explanation:


Introduction / Context:
The question targets where interface implementation is allowed in C#. Understanding which type categories can implement interfaces is foundational for good design.



Given Data / Assumptions:

  • Candidates: Class, Enum, Structure, etc.


Concept / Approach:
In C#, classes and structs (value types) can implement interfaces. Enums and namespaces cannot. “Data” is not a C# type category. Therefore, only (2) Class and (4) Structure are valid implementers among the listed options.



Step-by-Step Solution:

Check Class → Yes: class C : IExample { … } Check Enum → No: enums cannot implement interfaces in C# exams’ scope. Check Structure → Yes: struct S : IExample { … } Check Namespace → No: namespaces cannot implement anything; they only organize code. “Data” → Not a C# type category.


Verification / Alternative check:
Try compiling enum E : IExample { A } in C#; it fails. A struct/class implementing an interface compiles.



Why Other Options Are Wrong:
They include invalid categories (1, 3, 5) or omit necessary valid ones.



Common Pitfalls:
Confusing enum abilities with those of classes/structs; treating “namespace” as a type.



Final Answer:
2, 4

More Questions from Interfaces

Discussion & Comments

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