OOPS in C# – Interface polymorphism Part 5
Scenario:-
Different implementations for both interface and class.
public interface MyInterface1
{
int foo();
}
public interface MyInterface2
{
int foo();
}
public class MyClass : MyInterface1, MyInterface2
{
int a = 10;
#region MyClass Members
public int foo()
{
return a;
}
#endregion
#region MyInterface1 Members
int MyInterface1.foo()
{
return 11;
}
#endregion
#region MyInterface2 Members
int MyInterface2.foo()
{
return 12;
}
#endregion
}
In this case
MyClass obj = new MyClass();
MyInterface1 obj2 = (MyInterface1)obj;
MyInterface2 obj3 = (MyInterface2)obj;
obj.foo(); //Returns 10
obj2.foo(); //Returns 11
obj3.foo(); //Returns 12