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

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

Choose your learning style9 modes available
Recall & Review
beginner
What is explicit interface implementation in C#?
It is a way to implement interface members so they are only accessible through the interface, not through the class instance directly.
Click to reveal answer
intermediate
Why use explicit interface implementation?
To avoid name conflicts when multiple interfaces have members with the same name, or to hide interface methods from the class's public API.
Click to reveal answer
beginner
How do you declare an explicit interface implementation in C#?
Use the interface name followed by a dot before the member name, for example: void IInterface.Method().
Click to reveal answer
beginner
Can you call an explicitly implemented interface method directly from a class instance?
No, you must cast the class instance to the interface type first to call the method.
Click to reveal answer
intermediate
What happens if two interfaces have methods with the same signature and you implement them explicitly?
You can provide separate implementations for each interface method, avoiding conflicts and clarifying which method belongs to which interface.
Click to reveal answer
How do you call an explicitly implemented interface method from a class instance obj?
Aobj->Method()
Bobj.Method()
C((InterfaceType)obj).Method()
DInterfaceType.Method(obj)
Which syntax correctly declares an explicit interface implementation for method Show() in interface IDisplay?
Avoid IDisplay.Show()
Bpublic void Show()
CIDisplay.Show()
Dpublic IDisplay.Show()
What is a main benefit of explicit interface implementation?
AIt allows hiding interface methods from the class's public API
BIt automatically implements all interface methods
CIt makes interface methods public by default
DIt allows interface methods to be static
If a class implements two interfaces with the same method name, how can explicit implementation help?
ABy merging both methods into one
BBy providing separate implementations for each interface method
CBy ignoring one interface method
DBy renaming the class
Which statement is true about explicit interface implementation?
AExplicit interface methods can be called without casting
BExplicit interface methods are inherited by derived classes
CExplicit interface methods cannot be private
DExplicit interface methods do not have access modifiers
Explain how explicit interface implementation works and why you might use it.
Think about how to keep interface methods separate from class methods.
You got /4 concepts.
    Describe how to call an explicitly implemented interface method from an object instance.
    Remember explicit methods are hidden from the class itself.
    You got /3 concepts.