Hot Area:

HOTSPOT
A developer designs an interface that contains the following code:

For each of the following statements, select Yes if the statement is true. Otherwise, select No.
Hot Area:

HOTSPOT
A developer designs an interface that contains the following code:

For each of the following statements, select Yes if the statement is true. Otherwise, select No.
Hot Area:

Answer:



Leave a Reply 12

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


Chriss

Chriss

Should be no, yes, no
Because Class2 cannot call the method Method directly due to the explicit implementation of the interface method.
Casting Class1 instance to the interface will expose the explicit implementation such that the NotImplementedException will be thrown

Areks

Areks

can someone comment ? for me it’s no,no,no. Casting Class1 instance to interface is not throwing any exceptions…

Pascal

Pascal

yes no no, tested n proved

upmass

upmass

Correct answer is Yes, No, No
Verified.

1. If you try call Method from instance of Class2 IntelliSense set error notificantion and you can’t compile it.
2. Whe can cast an istance of Class1 into INewInterface and exception will not be throw
3. Class2 uses an explicit implementation of INewInterface because signature of method contains INewInterface’s pointer and doesn’t contain public modificator

aaaaa

aaaaa

absolutely yes,yes,yes

oasdbeq

oasdbeq

Haaaaaadddiiiii babaccccıııım yaaaaa

oasdbeq

oasdbeq

Eser Cihan was here !

xxamed

xxamed

ansver true

Jah

Jah

I’m surprised that no one got this correct. The answer is: No, No, No.
1. The question is about the exception. Exception won’t be thrown because the code will not even compile if you try to call Method1 from an instance of Class2. Compilation error is not a exception!
2. You can cast Class1 instance into INewInterface, the exception won’t be thrown.
3. This is implicit implementation: void Method1(){}, and this is explicit: void INewInterface.Method1(){}

JS1985

JS1985

You are right.
The Exception will only be thrown if Method1 is actually executed. It never will be executed, because it won’t compile. If you declare Method1() explicitly, you have to cast your object to that interface before calling Method1().

So this is perfectly valid:
Class2 classInstance = new Class2();
((INewInterface)classInstance).Method1();

But this won’t even compile:
Class2 classInstance = new Class2();
classInstance.Method1();

No
No
No

Linas

Linas

The question is too open. You can’t invoke Method1 on Class2, but you can invoke it if you cast Class2 into INewInterface. If you instantiate Class2 and then try to invoke the method, you can do that by casting to the interface. So does invoking the method mean that we also cast the object to actually invoke it, which will throw an exception, or just trying to invoke it on an obj of Class2, which can’t even happen and will not throw an exception?

Blasphem

Blasphem

I heard from an instructor that Microsoft don’t make “compilation mistakes” as a trap for exams questions.
Theyr code would allways compile, except if they implicitly says it doesnt, so if they ask you wich kind of result would you get on a code where they forgot a semicolon, you have to assume this is a just a typo error on the question and do as if the code was valid.

So I would assume answers for this question are Yes, No, No.