Interfaces contain only the signature of the methods.
Interfaces describe common set of methods. An interface has no implementation on its own, because it contains only the definition of methods without their bodies.
Definition of the method contains method name, parameter’s name, and their data type.
Interface is declared by interface keyword.
Interfaces are used to apply multiple inheritance in code. By This feature interface is differ from abstract classes.
Interfaces can extend multiple interfaces so multiple inheritance is not the problem
Example:
Interface A
{
Void print ()
}
Interface B
{
Void print ()
}
Class C : A,B
{
Void A. print ()
{
Console.writeLine (“this is interface A’s method”);
}
Void B.print ()
{
Console.writeLine (“This is interface B’s method”);
}
Public static void main ()
{
C x= new C ();
A a=(A)x;
B b=(B)x;
a.print();
b.print();
}
No comments:
Post a Comment