Interface in c#

In this article, we will learn about Interface in c#.
  • 6873

Introduction

Multiple inheritance is a feature in that a class can inherit more than one class. Multiple inheritance can not be implemented in C#. It can only implemented with interfaces.

Important points about interface

  • Interface has no implementation. it has only signature.
  • All interfaces are by default public and abstract.
  • All Interface member also are public and can not have any access specifier.
  • Interface instance can not be created.
  • Interface can inherit other interface.
  • Class can inherit multiple interfaces.

Example

using System;

namespace Dotnetheaven

{

    interface Icar

    {

        int car();

 

    }

    interface IPlane

    {

        bool developer

        {

            get;

        }

    }

    class sharad : Icar, IPlane

    {

        public int car()

        {

            return 4;

        }

        public bool developer

        {

            get

            {

                return true;

            }

        }

    }

    class Program

    {

        static void Main(string[] args)

        {

            sharad mysupercar = new sharad();

            Console.WriteLine(" sharad have " + mysupercar.car() + (" car ") + " He is a Engineer " + mysupercar.developer);

            Console.ReadLine();

        }

    }

}

 

The output of above Program

Clipboard 220.jpg

© 2020 DotNetHeaven. All rights reserved.