Which two code segments should you use?

You are developing an application that includes the following code segment:

You need to implement the Open() method of each interface in a derived class named UseResources
and call the Open() method of each interface.
Which two code segments should you use? (Each correct answer presents part of the solution.
Choose two.)

You are developing an application that includes the following code segment:

You need to implement the Open() method of each interface in a derived class named UseResources
and call the Open() method of each interface.
Which two code segments should you use? (Each correct answer presents part of the solution.
Choose two.)

A.
Option A

B.
Option B

C.
Option C

D.
Option D

Explanation:
* An interface contains only the signatures of methods, properties, events or indexers. A class or
struct that implements the interface must implement the members of the interface that are
specified in the interface definition.
* Example:
interface ISampleInterface
{
void SampleMethod();
}
class ImplementationClass : ISampleInterface
{
// Explicit interface member implementation:
void ISampleInterface.SampleMethod()
{
// Method implementation.
}
static void Main()
{
// Declare an interface instance.
ISampleInterface obj = new ImplementationClass();
// Call the member.
obj.SampleMethod();
}
}



Leave a Reply 8

Your email address will not be published. Required fields are marked *


zerocool

zerocool

Should be C & D since methods declared in the interface are public by default.

zerocool

zerocool

Oh, just tested it out, A & C are correct.

fabrizio

fabrizio

D throws exception

TheCoder

TheCoder

A doesn’t specify the access modifier for both Open() methods in UseResources class, thus the default is private (hidden) and cant be called…

it C & D

Najlepszy Programista Swiata

Najlepszy Programista Swiata

A i C Patafiany !