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()
{ }
}
Discussion:
15 comments Page 2 of 2.
Rahul Raj said:
10 years ago
Correct Answer "E".
Because Fun1() in MyClass is Void Fun1() and should be Fun2 also Void IMyInterface.fun2().
And no need to write public because public is by default.
Output:
interface IMyInterface
{
void fun1();
void fun2();
}
class MyClass : IMyInterface
{
void IMyInterface.fun1()
{ }
void IMyInterface.fun2()
{ }
Because Fun1() in MyClass is Void Fun1() and should be Fun2 also Void IMyInterface.fun2().
And no need to write public because public is by default.
Output:
interface IMyInterface
{
void fun1();
void fun2();
}
class MyClass : IMyInterface
{
void IMyInterface.fun1()
{ }
void IMyInterface.fun2()
{ }
Karthik D V said:
9 years ago
Explicit implementation of interface may not be needed in this case.
Public void fun1 () { } // This will solve the problem.
So, answer E isn't mandatory!
Public void fun1 () { } // This will solve the problem.
So, answer E isn't mandatory!
Omkar said:
8 years ago
void fun1() must be public.
Jasir said:
2 years ago
@All. As per my knowledge;
1) You can't use Access Modifiers while explicit implementation of interfaces in the Derived Class.
2) All methods in interface derived class should have either implicit or explicit implementation of interfaces, you can't have a mixture of them.
1) You can't use Access Modifiers while explicit implementation of interfaces in the Derived Class.
2) All methods in interface derived class should have either implicit or explicit implementation of interfaces, you can't have a mixture of them.
Pallavi said:
2 years ago
Interface can be implemented explicitly using <InterfaceName>. <MemberName>.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers