10
Reply

Q: What will be output of following code ? interface IMyInterface { void fun1(); void fun2(); } class MyClass : IMyInterface { void fun1() { } void fun2() { } }

Rajesh Singh

Rajesh Singh

Dec 01, 2015
3.3k
0

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

    Ravi Patel
    November 01, 2016
    2

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

    Joginder Banger
    October 03, 2016
    1

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

    Khaleek Ahmad
    February 02, 2017
    0

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

    manisha verma
    November 14, 2016
    0

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

    Joginder Banger
    October 03, 2016
    0

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

    keshav kothari
    July 26, 2016
    0

    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/

    vijay sekaran
    March 23, 2016
    0

    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.

    Rajesh Singh
    February 07, 2016
    0

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

    Arup
    February 07, 2016
    0

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

    Rajesh Singh
    December 01, 2015
    0