Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to explicitly implement the interface method.
C Sharp (C#)
interface IExample {
void Show();
}
class Demo : IExample {
void IExample.[1]() {
Console.WriteLine("Explicit implementation");
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different method name than the interface method.
Forgetting to prefix the method with the interface name.
✗ Incorrect
The method name must match the interface method exactly for explicit implementation.
2fill in blank
mediumComplete the code to call the explicitly implemented interface method from an interface reference.
C Sharp (C#)
interface IExample {
void Show();
}
class Demo : IExample {
void IExample.Show() {
Console.WriteLine("Explicit implementation");
}
}
class Program {
static void Main() {
Demo obj = new Demo();
IExample iobj = obj;
iobj.[1]();
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to call the method directly from the class instance.
Using a wrong method name.
✗ Incorrect
You must call the interface method name through the interface reference.
3fill in blank
hardFix the error in the explicit interface implementation method signature.
C Sharp (C#)
interface IExample {
void Show();
}
class Demo : IExample {
void IExample.[1]() {
Console.WriteLine("Explicit implementation");
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Adding 'public' or other access modifiers to explicit interface methods.
Using a different method name than the interface.
✗ Incorrect
Explicit interface implementations cannot have access modifiers like 'public'.
4fill in blank
hardFill both blanks to explicitly implement two interface methods correctly.
C Sharp (C#)
interface IFirst {
void MethodA();
}
interface ISecond {
void MethodB();
}
class Demo : IFirst, ISecond {
void IFirst.[1]() {
Console.WriteLine("First method");
}
void ISecond.[2]() {
Console.WriteLine("Second method");
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up method names between interfaces.
Using incorrect method names.
✗ Incorrect
Each method must match its interface method name exactly for explicit implementation.
5fill in blank
hardFill all three blanks to explicitly implement an interface and call its method correctly.
C Sharp (C#)
interface IExample {
void Show();
}
class Demo : IExample {
void IExample.[1]() {
Console.WriteLine("Explicit implementation");
}
}
class Program {
static void Main() {
Demo obj = new Demo();
IExample iobj = [2];
iobj.[3]();
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names for the interface reference.
Calling the method directly from the class instance instead of the interface reference.
✗ Incorrect
The method name must match the interface method, the interface reference must be assigned correctly, and the method called must be the interface method.