0
0
C Sharp (C#)programming~5 mins

Multiple interface implementation in C Sharp (C#) - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does multiple interface implementation mean in C#?
It means a class can use more than one interface at the same time, allowing it to promise to do multiple sets of actions.
Click to reveal answer
beginner
How do you declare a class that implements two interfaces named <code>IWalk</code> and <code>IRun</code>?
Use a comma to separate interfaces like this:<br><pre>class Animal : IWalk, IRun { }</pre>
Click to reveal answer
intermediate
Can a class implement two interfaces that have methods with the same name?
Yes, but you may need to use explicit interface implementation to avoid confusion and specify which method belongs to which interface.
Click to reveal answer
intermediate
What is explicit interface implementation in multiple interface implementation?
It is a way to write methods so they only work when accessed through the interface, helping to handle method name conflicts.
Click to reveal answer
beginner
Why is multiple interface implementation useful?
It helps a class to follow many different contracts or roles, making code flexible and easier to organize.
Click to reveal answer
How do you declare a class that implements two interfaces IRead and IWrite?
Aclass File implements IRead, IWrite { }
Bclass File : IRead & IWrite { }
Cclass File : IRead, IWrite { }
Dclass File : IRead.IWrite { }
If two interfaces have a method with the same name, how can a class implement both?
AUse explicit interface implementation
BRename one method in the class
CYou cannot implement both
DUse inheritance instead
Which keyword is used to implement interfaces in a class?
A:
Bimplements
Cextends
Dinherits
Can a class implement zero or more interfaces?
ANo, at least one
BYes, zero or more
CNo, only one
DOnly zero
What happens if a class implements an interface but does not provide all methods?
AInterface methods are ignored
BIt works fine
CRuntime error
DCompilation error
Explain how multiple interface implementation works in C# and why it is useful.
Think about how a class can promise to do many things by following many contracts.
You got /4 concepts.
    Describe explicit interface implementation and when you would use it.
    Consider when two interfaces have the same method name.
    You got /4 concepts.