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 or structs that implement the interface must provide the implementation.
Click to reveal answer
beginner
How do you declare an interface in C#?
Use the
interface keyword followed by the interface name and a block containing method/property signatures. For example:<br>public interface IExample { void DoWork(); }Click to reveal answer
intermediate
Can interfaces contain fields or constructors in C#?
No, interfaces cannot contain fields or constructors. They only declare method, property, event, or indexer signatures without implementation.
Click to reveal answer
intermediate
What access modifier is used for interface members in C#?
Interface members are implicitly public and cannot have access modifiers. All members declared in an interface are public by default.
Click to reveal answer
beginner
How does a class implement an interface in C#?A class implements an interface by using a colon <code>:</code> followed by the interface name, then providing implementations for all interface members. Example:<br><pre>public class Worker : IExample { public void DoWork() { /* code */ } }</pre>Click to reveal answer
Which keyword is used to declare an interface in C#?
✗ Incorrect
The
interface keyword is used to declare an interface in C#.Can an interface in C# contain method implementations?
✗ Incorrect
Starting with C# 8.0, interfaces can have default implementations for methods, but traditionally interfaces only declare signatures.
What access modifier do interface members have by default?
✗ Incorrect
Interface members are implicitly public and cannot have other access modifiers.
How does a class indicate it implements an interface?
✗ Incorrect
In C#, a class implements an interface by using a colon ':' followed by the interface name.
Which of these can NOT be declared inside an interface?
✗ Incorrect
Interfaces cannot contain fields; they only declare signatures for methods, properties, events, and indexers.
Explain how to declare an interface in C# and how a class implements it.
Think about the contract nature of interfaces and how classes fulfill that contract.
You got /4 concepts.
What are the limitations of interfaces in C# regarding members they can contain?
Consider what an interface represents and what it cannot do.
You got /4 concepts.