Recall & Review
beginner
What is an interface in C#?
An interface in C# is like a contract that defines a set of methods and properties without implementing them. Classes that use the interface promise to implement those methods and properties.
Click to reveal answer
beginner
Why do we say an interface acts as a contract?
Because it sets clear rules (methods and properties) that any class implementing it must follow, ensuring consistent behavior across different classes.Click to reveal answer
intermediate
Can a class implement multiple interfaces in C#?Yes, a class can implement multiple interfaces, meaning it agrees to follow multiple contracts at the same time.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 breaks the contract by not providing all required methods or properties.Click to reveal answer
intermediate
How does using interfaces improve code flexibility?
Interfaces allow different classes to be used interchangeably if they follow the same contract, making code easier to extend and maintain.
Click to reveal answer
What does an interface in C# define?
✗ Incorrect
An interface only defines method and property signatures, acting as a contract without implementation.
If a class implements an interface, what must it do?
✗ Incorrect
Implementing an interface means the class must provide code for all its methods and properties.
Can a class implement more than one interface in C#?
✗ Incorrect
C# allows a class to implement multiple interfaces, combining multiple contracts.
What is the main benefit of using interfaces?
✗ Incorrect
Interfaces enable polymorphism by allowing different classes to follow the same contract and be used interchangeably.
What error occurs if a class does not implement all interface members?
✗ Incorrect
The compiler enforces the contract and will raise an error if the class does not implement all required members.
Explain the idea of an interface as a contract in C# using a real-life example.
Think about agreements you make in daily life that require you to do certain things.
You got /4 concepts.
Describe how interfaces help make code more flexible and easier to maintain.
Consider how different devices can use the same charger type because they follow the same standard.
You got /4 concepts.