This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
I answered c and d, but the correct answer is c and e. In line 1, the variable s at compile time is of reference type Super and at runtime is of type Test013. All method invocations are resolved at runtime. Hence, I feel the cast is not necessary. Am i right? any mistakes?
SCJP 1.4, SCWCD 1.4<br /> <br />Thanks in advance!<br />Jayashree.
Hello, As u only said that during compile time the variable s is of reference type Super. So, while compilation it checks whether the method method() is present or not for the class Super. And therefore it gives a compilation error. So, i guess the correct answers are C and E
Test013 object is created and a variable of type Super is holding it. This happens at runtime.
At compiler time the method is not visible for a variable of type Super, because it is not defined in it. So if we want to use the method, we have to cast it to a type where the method is defined, then only the compiler will realise that it is having such a method.