Pavan Satpute
Can I inherit one Interface from another Interface?If Yes How? If No Why?

If I have below Code

  1. public interface ItestA
  2. {
  3. void method1();
  4. }
  5. public interface ItestB : ItestA
  6. {
  7. void method2();
  8. }
By Pavan Satpute in C# on Sep 12 2019
  • Ishoo Anyal
    Oct, 2019 7

    Yes you can inherit one interface from another without implementing the method of inherited interface however once Say you have two interface IA and IB So you can do interface IA : IB {} without any problem, however when you inherit IA in some class then you need to implement methods of IA as well as IB

    • 4
  • Sanjay Gangurde
    May, 2020 18

    using System;
    public interface A
    {
    void mymethod1();
    void mymethod2();
    }

    public interface B : A
    {
    void mymethod3();
    }

    class Test : B
    {
    public void mymethod1()
    {
    Console.WriteLine(“Implement method 1”);
    }
    public void mymethod2()
    {
    Console.WriteLine(“Implement method 2”);
    }
    public void mymethod3()
    {
    Console.WriteLine(“Implement method 3”);
    }
    }
    class Program
    {
    static void Main(String[] args)
    {
    Test obj = new Test();
    obj.mymethod1();
    obj.mymethod2();
    obj.mymethod3();
    }
    }

    • 1
  • ramila raj
    Nov, 2019 8

    yes..because interface it not having method definition, once you inherited the inherited class will override all the methods inside the inheritance..you can check my youtube page for more interview questions like this..

    https://www.youtube.com/channel/UC3NEDQLo6r544wagWGWPGLg

    • 1
  • Munib Butt
    Apr, 2020 28

    Yes you can inherit one interface in another. However, when you implement the interface which has inherited another interface, you would have to implement the methods in both interfaces.

    • 0
  • Sid KC
    Apr, 2020 1

    Yes, We can inherit one interface from another interface. Later class that implements parent interface has to implement methods from child interface and parent interface. Example snippet: public class Test : ITest{public int sum(){throw new NotImplementedException();}public int sum1(){throw new NotImplementedException();}}public interface ITest1{int sum1(); }public interface ITest:ITest1{int sum();}

    • 0
  • sameer shaikh
    Feb, 2020 2

    You can't inherited because there is no inheritance concept this is Implementation .

    • 0
  • sameer shaikh
    Feb, 2020 2

    jnj

    • 0
  • Ashish MIshra
    Jan, 2020 27

    Yes, We one Interface can inherit from another interface and the class which inherit the interface must have to provide the implementation of the full chain inheritance.

    • 0
  • Sagar Raj
    Dec, 2019 22

    Yes you can Inherit one Interface from another Interface Basically interface will contain only constant varible and abstract method so when you inherit you need to provide implementation for the abstract method.For example
    interface car{
    abstract drive();
    }
    interface maruthi(brand name): car{
    abstract safety();
    //here drive method will also be there and safety method will also be there now the class which implents the maruthi interface need to provide implementation for drive and safety
    }

    • 0
  • Rahul singh
    Dec, 2019 10

    public interface ICollection : IEnumerable, IEnumerable

    • 0
  • Shekhar Kumar
    Nov, 2019 26

    Yes, one interface can inherit another interface.
    Now when ItestB gets inherited by a class then that class has to implement the methods of both interfaces.

    • 0
  • Yogesh Sevankar
    Oct, 2019 18

    Yes

    • 0

Most Popular Job Functions


MOST LIKED QUESTIONS