In C#, you cannot create a class that inherits from
more than one class. However, sometimes it is required to create a class that
inherits features from more than one class. This type of inheritance is known
as multiple inheritances. C# does not support the feature of multiple inheritance
for classes; however it is allow you to take the advantage of the multiple inheritance
feature by supporting the concept of interface
The following are some important characteristics of interface
·
An
Interface declared by using the interface keyword
·
You
cannot create the object of Interface
·
If
a class implements an interface ,then it must provide implementations for all
the methods of the interface
·
By
default interface is public
·
There
is no any field using in interface like int a=10;
·
static keyword is not allow in interface
[access-modifier] interface <Interface Name>
{
//method declarations
}
In the preceding syntax:
·
Access-modifier : Specifies the scope
in which the interface can be accessed
·
Interface : Represents a
keyword that declares an interface
·
Interface Name: specified name for interface
For Example:
public interface MyInterface
{
void displaymarks(int
m);
}
public class MyClass:MyInterface
{
private int marks;
public void
displaymarks(int m)
{
marks
= m;
MessageBox.Show("marks"
+ marks);
}
}
0 comments:
Post a Comment