Recall & Review
beginner
What is an interface in C#?
An interface in C# is a contract that defines a set of methods and properties without implementing them. Classes that implement the interface must provide the implementation for all its members.
Click to reveal answer
beginner
How do you declare that a class implements an interface in C#?You use a colon (:) after the class name followed by the interface name. For example: <br><code>public class MyClass : IMyInterface { }</code>Click to reveal answer
intermediate
Can a class implement multiple interfaces in C#? How?Yes, a class can implement multiple interfaces by listing them separated by commas after the colon. For example:<br><code>public class MyClass : IFirst, ISecond { }</code>Click to reveal answer
intermediate
What happens if a class does not implement all members of an interface it declares?The C# compiler will give an error because the class must provide implementations for all interface members unless the class is declared abstract.Click to reveal answer
advanced
Explain explicit interface implementation in C#.
Explicit interface implementation means implementing interface members so they can only be accessed through the interface, not the class instance directly. This is done by prefixing the member with the interface name, like:<br><code>void IMyInterface.Method() { }</code>Click to reveal answer
How do you declare that a class implements an interface named IExample?
✗ Incorrect
In C#, a class implements an interface using a colon (:), not 'implements' or 'inherits'.
What must a class do when it implements an interface?
✗ Incorrect
A class must implement all members of the interface unless it is abstract.
Can a class implement more than one interface?
✗ Incorrect
C# allows multiple interfaces to be implemented by listing them separated by commas.
What is explicit interface implementation used for?
✗ Incorrect
Explicit implementation hides interface members so they are accessible only through the interface type.
If a class does not implement all interface members, what happens?
✗ Incorrect
The compiler requires all interface members to be implemented unless the class is abstract.
Describe how to implement an interface in a C# class and what rules must be followed.
Think about the syntax and what the compiler expects.
You got /4 concepts.
Explain the difference between implicit and explicit interface implementation in C#.
Consider how you access the implemented methods.
You got /4 concepts.