A class that implements an interface can explicitly implement a member of that interface. When a member is explicitly implemented, it cannot be accessed through a class instance, but only through an instance of the interface.
Interface :-
interface Idemo
{
Int32 height();
Int32 Width();
}
{
Int32 height();
Int32 Width();
}
class Program : Idemo
{
Int32 intHeight;
Int32 intWidth;
public Program(Int32 Height, Int32 Width)
{
intHeight = Height;
intWidth = Width;
}
Int32 Idemo.height()
{
return intHeight;
}
Int32 Idemo.Width()
{
return intWidth;
}
static void Main(string[] args)
{
Program prg = new Program(30, 40);
Idemo myDemo = (Idemo) prg;
System.Console.WriteLine("Length {0}", myDemo.Width());
System.Console.WriteLine("Height {0}", myDemo.height());
Console.Read();
}
}
{
Int32 intHeight;
Int32 intWidth;
public Program(Int32 Height, Int32 Width)
{
intHeight = Height;
intWidth = Width;
}
Int32 Idemo.height()
{
return intHeight;
}
Int32 Idemo.Width()
{
return intWidth;
}
static void Main(string[] args)
{
Program prg = new Program(30, 40);
Idemo myDemo = (Idemo) prg;
System.Console.WriteLine("Length {0}", myDemo.Width());
System.Console.WriteLine("Height {0}", myDemo.height());
Console.Read();
}
}
OUTPUT:-
Length: 30 Width: 40
No comments :
Post a Comment