PrepAway - Latest Free Exam Questions & Answers

17 Comments on “Hot Area:

  1. Chriss says:

    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




    1



    8
  2. upmass says:

    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




    17



    6
    1. ronzhong says:

      1. Method1 wasn’t implemented with public accessor and it’s not allowed
      2. Class1 didn’t implement Method1(), although it can be compiled, but it will have run-time error.
      3. Explicit implementation.




      0



      1
      1. ronzhong says:

        1.Y => Method1 wasn’t implemented with public accessor, an compile error will be thrown
        2.N => Class1 didn’t implement Method1(), although it can be compiled, but it will have run-time error.
        2.N




        0



        1
  3. Jah says:

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




    20



    0
    1. JS1985 says:

      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




      5



      0
    2. khoa_chung_89 says:

      Could you explain the second answer more? I think Class1 inherits from Class2 so casting it to INewInterface and call Method1 should throw exception. I have tried with vs2017 and it throws exception. So i think the answer should be No, Yes, No




      0



      0
  4. Linas says:

    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?




    0



    0
    1. Blasphem says:

      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.




      5



      0

Leave a Reply