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 c# console application?

0 Answers  


Can an Assembly have multiple versions

13 Answers   TCS,


What's c# ?

0 Answers  


What is multicast delegate explain with example?

0 Answers  


Why does dllimport not work for me?

0 Answers  






What is int32 in c#?

0 Answers  


Explain how to implement delegates in c#.net

0 Answers  


Which of these statements correctly declares a two-dimensional array in c#?

0 Answers  


If you define a user defined data type by using the class keyword, is it a value type or reference type?

0 Answers  


How can I access the registry from c# code?

0 Answers  


What is the Use Of Interfaces? For example I have a interface as shown below? Interface IMyInterface { public void MyMethod(); } class MyClass : IMyInterface { public void Mymethod() { Some Code } } class Program { static void Main(string[] args) { MyClass obj = new MyClass(); obj.MyMethod(); } } Here What is My Question is? If i remove Interface and run this code, it will executed then what is the Use of the interface? Can any one give me the solution for this Problem? Thanks in Advance!

1 Answers   HCL,


Which one is trusted and which one is untrusted?

0 Answers  


Categories