aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes q from jiris.com on overriding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "q from jiris.com on overriding" Watch "q from jiris.com on overriding" New topic
Author

q from jiris.com on overriding

JayaSiji Gopal
Ranch Hand

Joined: Sep 27, 2004
Posts: 303


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.
Animesh Shrivastava
Ranch Hand

Joined: Jul 19, 2004
Posts: 298
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
Adeeb Abdul Karim
Greenhorn

Joined: Dec 22, 2004
Posts: 8
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.

So E is correct.


�That which begins, also ends.�
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Yes, it's a simple as that: class Super does not have a method called "method".


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
 
 
subject: q from jiris.com on overriding