using System;
namespace ConsoleApplication1
{
interface IMyInterface
{
int intVar;
}
class MyClass: IMyInterface
{
public void show()
{
Console.WriteLine("welcome at TutorialRide");
}
}
class Program
{
static void Main(string[] args)
{
MyClass obj = new MyClass();
obj.show();
Console.ReadLine();
}
}
}
using System;
namespace ConsoleApplication1
{
interface IMyInterface
{
public void myFunction()
{
Console.WriteLine("Interface Demo");
}
}
class MyClass: IMyInterface
{
public void show()
{
Console.WriteLine("welcome at TutorialRide");
}
}
class Program
{
static void Main(string[] args)
{
MyClass obj = new MyClass();
obj.show();
Console.ReadLine();
}
}
}
using System;
namespace ConsoleApplication1
{
interface IMyInterface
{
void myFunction();
}
class MyClass: IMyInterface
{
void myFunction()
{
Console.WriteLine("welcome at TutorialRide");
}
}
class Program
{
static void Main(string[] args)
{
MyClass obj = new MyClass();
// obj.myFunction();
Console.ReadLine();
}
}
}
using System;
namespace ConsoleApplication1
{
interface FirstInterface
{
void myFirstFunction();
}
interface SecondInterface
{
void mySecondFunction();
}
class MyClass : FirstInterface, SecondInterface
{
public void myFirstFunction()
{
Console.WriteLine("myFirstFunction() is called");
}
public void mySecondFunction()
{
Console.WriteLine("mySecondFunction() is called");
}
}
class Program
{
static void Main(string[] args)
{
MyClass obj = new MyClass();
obj.myFirstFunction();
obj.mySecondFunction();
Console.ReadLine();
}
}
}
using System;
namespace ConsoleApplication1
{
interface FirstInterface
{
void myFunction();
}
interface SecondInterface
{
void myFunction();
}
class MyClass : FirstInterface, SecondInterface
{
void FirstInterface.myFunction()
{
Console.WriteLine("myFunction() is from FirstInterface");
}
void SecondInterface.myFunction()
{
Console.WriteLine("myFunction() is from SecondInterface");
}
}
class Program
{
static void Main(string[] args)
{
MyClass obj = new MyClass();
FirstInterface FI = new MyClass();
FI.myFunction();
SecondInterface SI = new MyClass();
SI.myFunction();
Console.ReadLine();
}
}
}
using System;
namespace ConsoleApplication1
{
interface IEmployee
{
int empID
{
get;
set;
}
string empName
{
get;
set;
}
}
class Employee:IEmployee
{
int id;
string name;
public int empID
{
get
{
return id;
}
set
{
id = value;
}
}
public string empName
{
get
{
return name;
}
set
{
name = value;
}
}
}
class Program
{
static void Main(string[] args)
{
Employee emp = new Employee();
System.Console.Write("Enter employee ID: ");
emp.empID = int.Parse(System.Console.ReadLine());
Console.Write("Enter the name of the employee: ");
emp.empName = System.Console.ReadLine();
System.Console.WriteLine("The employee information:");
System.Console.WriteLine("Employee ID: {0}", emp.empID);
System.Console.WriteLine("Employee name: {0}", emp.empName);
Console.ReadLine();
}
}
}
using System;
namespace ConsoleApplication1
{
interface FirstInterface
{
void myFirstFunction();
}
interface SecondInterface:FirstInterface
{
void mySecondFunction();
}
class MyClass :SecondInterface
{
public void myFirstFunction()
{
Console.WriteLine("myFirstFunction() is from FirstInterface");
}
public void mySecondFunction()
{
Console.WriteLine("mySecondFunction() is from SecondInterface");
}
}
class Program
{
static void Main(string[] args)
{
MyClass obj = new MyClass();
obj.myFirstFunction();
obj.mySecondFunction();
Console.ReadLine();
}
}
}
Abstract Class | Interface |
---|---|
A class may inherit only one abstract class. | A class may inherit more than one interface. |
An abstract class can have abstract or non-abstract methods. | An interface cannot provide any implementation, only the signature. |
An abstract class can contain access modifiers for members. | An interface cannot have access modifiers. By default all members are public. |
An abstract class can have fields | Interfaces cannot contain fields |