Inheritance is way or technique by using one class can access details of other class. What happen if you wants to access details of more than one class and implement them with in current class.
C# cannot have more than one super-class. We can only do this by using Interface.
class class-name : A, B , C
{
//here detail of implementaion
// A, B , C is other classes
}
Above is not allowed in C#.
We also know that C# not support multiple inheritance because by using this it create problems for developer but also create a lot of confusion. To overcome with this issue C# supports multiple inheritance by using Interface.
An Interface in C# is reference type. There is some major different between class and interface.
- Interface members cannot be declare as static.
- Interface cannot declare constructor and destructors.
- All members of an Interface default public and abstract.
- Interface methods are abstract so they do not include implementation of the method.
Structure of Interface
An Interface only define the methods, properties, indexers and events but not their implementation. It is the responsibility of that class that implements the interface.
Interface name-of-interface
{
// methods are here to go....
}
-
Interface first-interface
{
int Addition( int x, int y);
}
-
Interface Second-interface
{
int Multiple( int a, int b);
}
In first interface only one method Addition and in second interface also one method Multiple.
-
Interface Third-interface
{
int Divide ( int c, int d) ;
}
What happen if third interface inherit both of the A , B interface
Interface Third-interface : first-interface , Second-interface
{
Chaitanya PatelPosted Jul 30, 2014, 1:37 PM
nice effort i like it....