Can I inherit one Interface from another Interface?If Yes How? If No Why?
Pavan Satpute
Select an image from your device to upload
If I have below Code
public interface ItestA{ void method1();}public interface ItestB : ItestA{ void method2();}
public interface ItestA
{
void method1();
}
public interface ItestB : ItestA
void method2();
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(); }}
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
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.
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.
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 exampleinterface 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}
public interface ICollection : IEnumerable, IEnumerable
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.