C# Programming - Interfaces - Discussion

Discussion Forum : Interfaces - General Questions (Q.No. 1)
1.
Which of the following statements is correct about the C#.NET code snippet given below?
interface IMyInterface
{ 
    void fun1(); 
    int fun2();
}
class MyClass: IMyInterface
{ 
    void fun1()
    { } 
    int IMyInterface.fun2()
    { } 
}
A function cannot be declared inside an interface.
A subroutine cannot be declared inside an interface.
A Method Table will not be created for class MyClass.
MyClass is an abstract class.
The definition of fun1() in class MyClass should be void IMyInterface.fun1().
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
15 comments Page 2 of 2.

Sudhakar said:   1 decade ago
void IMyInterface.fun1()
int IMyInterface.fun2()

(or)

public void fun1()
public int fun2()


As per multiple choice answer should be 'E'.

Mahdi said:   1 decade ago
The answer is wrong because
1.fun2 should return an int value
2. fun1 and fun2 in Myclass should be public

Pallavi said:   2 years ago
Interface can be implemented explicitly using <InterfaceName>. <MemberName>.

Pramod Khandare said:   1 decade ago
No need to give Interface name while giving definition to method void fun1().

Omkar said:   8 years ago
void fun1() must be public.


Post your comments here:

Your comments will be displayed after verification.