Friday, July 13, 2007

Interface Example1

interface ISample1
{
int sum();
}
interface ISample2
{
int sum();
}
public class A : ISample1, ISample2
{
// There should be no access specifier (it will give build error).
int ISample1.sum()
{
return 10;
}
// There should be no access specifier (it will give build error).
int ISample2.sum()
{
return 20;
}
}
class Program
{
static void Main(string[] args)
{
A a = new A();
ISample1 is1 = (ISample1)a;
Console.WriteLine(is1.sum().ToString());
ISample2 is2 = (ISample2)a;
Console.WriteLine(is2.sum().ToString());
}
}

No comments: