PrepAway - Latest Free Exam Questions & Answers

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.)

PrepAway - Latest Free Exam Questions & Answers

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();
}
}

7 Comments on “Which two code segments should you use?

  1. Pascal says:

    Stop confusing people, an explicit implementation does not include the public keyord once you implement it, only if you choose to add it, only implicit implementation includes the public property., better to leave the void in its default for explicits, so its A and c




    30



    0
  2. cristis says:

    A&C

    interface IFile
    {
    void Open();
    }

    interface IDbConnection
    {
    void Open();
    }

    // Implicit
    class UserResources : IFile, IDbConnection
    {
    // Generated implementation
    void IFile.Open()
    {
    throw new NotImplementedException();
    }

    // Generated implementation
    void IDbConnection.Open()
    {
    throw new NotImplementedException();
    }
    }

    class UserResourcesExplicit : IFile, IDbConnection
    {
    public void Open()
    {
    throw new NotImplementedException();
    }

    void IDbConnection.Open()
    {

    }
    }

    class Test
    {
    public Test()
    {
    var manager = new UserResources();
    ((IFile)manager).Open();
    ((IDbConnection)manager).Open();
    }
    }




    1



    0

Leave a Reply