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
Why is main static in c#?
what is the equivalent to regsvr32 and regsvr32 /u a file in .net development?
Is c# used for any core features of windows vista?
Why do we need static in c#?
How do you escape a character?
What is use of abstract class in c#?
Is arraylist faster than linkedlist?
What is dll in c#?
What is deadlock in c#?
What is check/uncheck?
What is constructor overloading in c#?
What is difference between dictionary and list in c#?
List down the reason behind the usage of c# language.
What is c-sharp (c#)?
What is the use of generics in c#?