What is an interface class? Explain with example.

1 Answers

Ravi Vishwakarma
Ravi Vishwakarma

An Interface is an abstract class which has only public abstract methods, and the methods only have the declaration and not the definition. These abstract methods must be implemented in the inherited classes.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Hello
{
 interface IListOfTuto // interface
 {
  void SetTutorial(int pID, string pName);
  String GetTutorial();
 }
 class HelloWorld : IListOfTuto // class
 {
  protected int TutorialID;
  protected string TutorialName;
  public void SetTutorial(int pID, string pName)
  {
   TutorialID = pID;
   TutorialName = pName;
  }
  public String GetTutorial()
  {
   return TutorialName;
  }
  static void Main(string[] args)
  {
   HelloWorld pTutor = new HelloWorld();
   pTutor.SetTutorial(1,'.Net by mindstick.com');
   Console.WriteLine(pTutor.GetTutorial());
   Console.ReadKey();
  }
 }
}

Answer