INTERFACES OOPS Concept
All the classes will Inherit interfaces methods. Abstract classes serve some similar operation of interfaces. Inside the interface methods does not implemented. Interface will be define methods, properties and events
Interface is not a class it will represent with the key word 'interface'
Interface name contain with I prefix in the interface name.
Interface contain public as its modifiers.
Interface methods will be implemented in the class file which inherited interfaces.
A class can be Inherit more interfaces. Interfaces will support multiple inheritance.
code:
//Interface contain methods without implementation inside the interface
public interface Ivalue
{
string Name();
}
//Interface method declare in the inherited classes of the intefaces
Public class Operation : Ivalue
{
public string Name()
{
return "MANOJ KUMAR";
}
}
SAMPLE PROJECT
public interface Isample
{
string fname
{
get;
set;
}
string lname
{
get;
set;
}
string Name();
}
//Class inherited with interfaces
public class Operation : Isample
{
protected string _fname;
protected string _lname;
public string fname
{
get
{
return _fname;
}
set
{
_fname = value;
}
}
public string lname
{
get
{
return _lname;
}
set
{
_lname = value;
}
}
public string Name()
{
return "First Name is " + fname + " & Last Name is " + lname;
}
}
class Program
{
static void Main(string[] args)
{
Isample sam = new Operation();
sam.fname = "Manoj";
sam.lname = "Kumar";
Console.WriteLine(sam.Name());
Console.ReadLine();
}
}
}
Result Set