Interfaces
using System;
// An interface is a collection of abstract methods. A class implements an interface, thereby inheriting the abstract methods of the interface.
interface Employee
{
string getFname();
string getLname();
}
class EmployeeDetails:Employee // EmployeeDetails implements the interface Employee.So it have to define all the methods in the interface.
{
string fname="John", lname="Smith";
public string getFname()
{
return fname;
}
public string getLname()
{
return lname;
}
static void Main(string[] args)
{
EmployeeDetails e = new EmployeeDetails(); // Creating the object of class
String first_name = e.getFname();
String last_name = e.getLname();
Console.WriteLine("Name of the employee: " + first_name + " " + last_name);
Console.ReadLine();
}
}
Output:
Name of the employee: John Smith