Rajesh Singh
Q: What will be output of following code ? interface IMyInterface { void fun1(); void fun2(); } class MyClass : IMyInterface { void fun1() { } void fun2() { } }
By Rajesh Singh in .NET on Dec 01 2015
  • Ravi Patel
    Nov, 2016 1

    compile time error because Myclass is not implementing the method of IMyInterface . interface implented method must be public.

    • 2
  • Joginder Banger
    Oct, 2016 3

    Try this type...... public interface IMyInterface { void fun1();void fun2();}class MyClass : IMyInterface {void IMyInterface.fun1(){ }void IMyInterface.fun2(){}}

    • 1
  • Manoth Kumar
    Nov, 2018 26

    Compile time error. In derived class, implemented methods should be declared as public.interface IMyInterface { void fun1(); void fun2(); } class MyClass : IMyInterface { public void fun1() {} public void fun2(){ }}

    • 0
  • Khaleek Ahmad
    Feb, 2017 2

    It will give compile time error be as MyClass should implement all interface member. Because all interface function definition should be public in class.

    • 0
  • manisha verma
    Nov, 2016 14

    above code will give the error please tyr below:-interface IMyInterface{void fun1();void fun2();}class MyClass : IMyInterface{public void fun1(){}public void fun2(){}}

    • 0
  • Joginder Banger
    Oct, 2016 3

    For more information please read this link : https://msdn.microsoft.com/en-us/library/ms173157.aspx

    • 0
  • keshav kothari
    Jul, 2016 26

    interface IMyInterface {void fun1();void fun2(); }class Class1 : IMyInterface {public void fun1() { } public void fun2() { } }

    • 0
  • vijay sekaran
    Mar, 2016 23

    MyClass access modifiers functions are private now. So you cont build this one.You will get bellow error message:"Error 1 'ConsoleApplication1.Program.MyClass' does not implement interface member 'ConsoleApplication1.Program.IMyInterface.fun2()'. 'ConsoleApplication1.Program.MyClass.fun2()' cannot implement an interface member because it is not public. D:\Work\Test\ConsoleApplication1\ConsoleApplication1\Program.cs 18 15 ConsoleApplication1 "http://asp-net-corner.blogspot.in/

    • 0
  • Rajesh Singh
    Feb, 2016 7

    Hi Arup,Thanks for reply. As you said all members of interface are by default public that is correct. The members of class, MyClass is private, since access modifiers are not mention here, after implementing interface. So it will not compile. Plz let me know if you have any dought.

    • 0
  • Arup
    Feb, 2016 7

    It will not show any error during compile time. please check this code, all members inside interface are public bydefault

    • 0
  • Rajesh Singh
    Dec, 2015 1

    Ans: It will not compile because access modifier of fun1() and fun2() are private. It should be public.

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS