An interface defines a series of members the implementer must implement.
An interface itself doesn't provide any implementation.
A class can implement any number of interfaces.
A struct can implement interface as well.
An interface can only have methods, properties, events and indexers.
The following code defines an interface.
using System;
interface Printable{
void Print();
}
class Rectangle : Printable{
int Width;
public void Print(){
Console.WriteLine("Width:"+Width);
}
}
class Test
{
static void Main()
{
Printable r = new Rectangle();
r.Print();
}
}
The output:
Width:0
java2s.com | Contact Us | Privacy Policy |
Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
All other trademarks are property of their respective owners. |