Home » Microsoft » 70-483 » Which two code segments should you use?
You are developing an application that includes the following code segment:
You need to implement both Start() methods in a derived class named UseStart that uses the Start() 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
E. Option E
F. Option F
Correct Answer: BE
Explanation/Reference:
B:
* Implementing Multiple Interfaces
A class can implement multiple interfaces using the following syntax: C#
public class CDAndDVDComboPlayer : ICDPlayer, IDVDPlayer
If a class implements more than one interface where there is ambiguity in the names of members, it is resolved using the full qualifier for the property or method name. In other words, the derived class can resolve the conflict by using the fully qualified name for the method to indicate to which interface it belongs
* In C#, both inheritance and interface implementation are defined by the : operator, equivalent to extends and implements in Java. The base class should always be leftmost in the class declaration.
The answers are: C en D
But D is a bit confusing because it’s missing information that shows that IHome and IOffice is implemented in the class.
it would have been properly to show the 1st line of the class like the answers B en D: “class UseStart : IHome, IOffice” and the required implemention of the interface methods.
//C and D –> correct answer
class Program
{
static void Main(string[] args)
{
var starter = new UseStart();
((IHome)starter).Start();
((IHome)starter).Start();
}
}
interface IHome {
void Start();
}
interface IOffice {
void Start();
}
class UseStart : IHome, IOffice
{
void IHome.Start()
{
}
void IOffice.Start() {
}
}
C, D is the correct answer, I tested below code
class UseStart : IHome, IOffice
{
void IOffice.start()
{
MessageBox.Show(“IOffice”);
}
void IHome.start()
{
MessageBox.Show(“IHome”);
}
}
public void test()
{
var starter = new UseStart();
((IHome)starter).start();
((IOffice)starter).start();
}
Who comes up with these “correct” answers? It kind of defeats the purpose when you can’t trust the answer to be correct.
Ran it myself because I was bewildered. C, D is the correct answer
correct answer: C, D
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/interfaces/explicit-interface-implementation
correct answer: C, D
Explicitely implemented interfaces can’t be “public”, so shall be C and D.