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

Answers were Sorted based on User's Feedback



If there are 2 interface IParentInterface & IChildInterface as follows. interface IParentI..

Answer / 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

If there are 2 interface IParentInterface & IChildInterface as follows. interface IParentI..

Answer / vijay

In this scenario,
Whenever the child interface is called, by default
InterfaceMethod() of childe interface is gets called.

Is This Answer Correct ?    3 Yes 2 No

If there are 2 interface IParentInterface & IChildInterface as follows. interface IParentI..

Answer / anurag

use
void IChildInterface.InterfaceMethod(){}
don't use access modifier with explicit method.

Is This Answer Correct ?    2 Yes 4 No

Post New Answer

More C Sharp Interview Questions

What is difference between private and static constructor?

0 Answers  


How can you write a class to restrict that only one object of this class can be created (Singleton class)?

0 Answers  


What is the difference between proc. Sent by val and by sub?

0 Answers  


Howmany five tracing levels in System.Diagnostics.TraceSwitcher? Why they are using?

0 Answers   Siebel,


How?s method overriding different from overloading?

2 Answers   Visual Soft,






What is unmannaged code and will CLR handle this kind of code or not .

0 Answers   DELL,


What do you know about Translate Accelerator?

0 Answers   C DAC,


What is using directive in c#?

0 Answers  


Why are strings immutable in c#?

0 Answers  


What are custom exceptions? Why do we need them?

0 Answers  


How do you prevent a class from being inherited in c#?

0 Answers  


What is ildasm.exe used for?

0 Answers  


Categories