This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma 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.