Recall & Review
beginner
What are default interface methods in C#?
Default interface methods allow interfaces to provide a default implementation for methods. This means classes implementing the interface don't have to implement those methods unless they want to override the default behavior.
Click to reveal answer
beginner
How do you declare a default method in an interface?
Inside the interface, you define the method with a body using curly braces. For example:<br>
interface IExample { void Show() { Console.WriteLine("Hello"); } }Click to reveal answer
beginner
Can a class override a default interface method?Yes, a class implementing the interface can provide its own implementation of the default method, which will replace the default one.Click to reveal answer
intermediate
Why were default interface methods introduced in C#?
They were introduced to allow adding new methods to interfaces without breaking existing implementations. This helps evolve interfaces over time.
Click to reveal answer
intermediate
What happens if a class implements two interfaces with the same default method signature?The class must explicitly implement the method to resolve the conflict, otherwise the compiler will give an error.Click to reveal answer
What is the main benefit of default interface methods?
✗ Incorrect
Default interface methods allow interfaces to provide method implementations, so classes don't always have to implement them.
How do you provide a default implementation in an interface method?
✗ Incorrect
Default implementations are given by writing the method with a body inside the interface.
If a class implements an interface with a default method, what happens if the class does not implement that method?
✗ Incorrect
The class automatically uses the default implementation provided by the interface.
Can default interface methods access private members of the implementing class?
✗ Incorrect
Default interface methods cannot access private members of the implementing class.
What must a class do if it implements two interfaces with conflicting default methods?
✗ Incorrect
The class must explicitly implement the method to resolve the conflict.
Explain what default interface methods are and why they are useful.
Think about how interfaces used to work before default methods.
You got /3 concepts.
Describe how a class can override a default interface method and what happens if it does not.
Consider what happens when you want to change the default behavior.
You got /3 concepts.