Q:

What is an interface class? Give one example of it

0

What is an interface class? Give one example of it

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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.

There are few properties of the interface class,

  • Interfaces specify what a class must do and not how.
  • Interfaces can’t have private members.
  • By default, all the members of Interface are public and abstract.
  • The interface will always be defined with the help of the keyword ‘interface‘.
  • An interface cannot contain fields because they represent a particular implementation of data.
  • Multiple inheritances are possible with the help of Interfaces but not with classes.

Syntax for Interface Declaration:

interface  <interface_name >
{
    // declare Events
    // declare indexers
    // declare methods 
    // declare properties
}

Syntax for Implementing Interface:

class class_name : interface_name

Sample Example Code,

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DemoApplication
{
 interface ISampleInterface
 {
  void SetTutorial(int pID, string pName);
  String GetTutorial();
 }
 class ImplementationClass  : ISampleInterface
 {
  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)
  {
   ImplementationClass  pTutor = new ImplementationClass ();
   pTutor.SetTutorial(1,"C# interview Questions by Aticleworld.com");
   Console.WriteLine(pTutor.GetTutorial());
   Console.ReadKey();
  }
 }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# Interview Questions and Answers,You Need To Know

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
What is the advantage of interface class?... >>
<< What is the difference between an abstract functio...