If there are 2 interface IParentInterface &
IChildInterface as follows.
interface IParentInterface
{
void InterfaceMethod();
}
interface IChildInterface : IParentInterface
{
void InterfaceMethod();
}
Both the interface contains method with same name
InterfaceMethod().
How InterfaceMethod() will be handled in IChildInterface as
its deriving IParentInterface
Answer Posted / sagar
using explicit type casting this scenario is possible.
interface IParentInterface
{
void InterfaceMethod();
}
interface IChildInterface : IParentInterface
{
void InterfaceMethod();
}
class Parent : IChildInterface
{
void IParentInterface.InterfaceMethod()
{
Console.WriteLine("Parent Interface");
}
void IChildInterface.InterfaceMethod()
{
Console.WriteLine("Child Interface");
}
static void Main()
{
Parent p = new Parent();
IParentInterface i1 = p;
IChildInterface i2 = p;
i1.InterfaceMethod();
i2.InterfaceMethod();
Console.ReadLine();
}
}
| Is This Answer Correct ? | 14 Yes | 0 No |
Post New Answer View All Answers
Illustrate race condition?
Is it possible to have different access modifiers on the get/set methods of a property in c#?
What is the difference between Singleton design pattern and Factory design pattern?
Why do we use 0?
Why delegates are safe in c#?
What is double c#?
Explain how obfuscator works in .net
Can an array be null c#?
What is regex c#?
What is a verbatim string literal and why do we use it?
Why is c# good for games?
What is the main purpose of delegates in c#?
How do I create a new form in c#?
Why do I get a syntax error when trying to declare a variable called checked?
Is string null or empty?