<B>~James Baud</B><P>He who asks, is a fool for five minutes;<BR>but, he who does not ask, remains a fool forever. (Chinese proverb)
Originally posted by James Baud:
[B]I tried the Sun sample questions today at
WGS-PREX-J000: ePractice Sample Questions On item 6 the code goes like this:
Question: When inserted on line 10, which line will override the getType method and allow compilation to succeed?
Answer choices:
A o public Text getType(String a, int b, char c) {
B o public Text getType(int b, String a, char c) {
C o public String getType(String a, int b, char c) {
D o public String getType(int b, String a, char c) {
Sun's Answer:
Option C is correct because the method name, argument list, and return type are the same as the getType method defined in the IntType class. Overriding methods must be declared with the same
name, argument list, and return type as the overridden method.
Option A is incorrect because the return type is not the same as the getType method in the IntType class. Option B is incorrect because both the return type and argument list are different
from the getType method in the IntType class. Option D is incorrect because the argument list is different from the getType method in the IntType class.
My comment is this: Option C would have been correct if it had the static modifier for getType() method because it is being called from the static method main().
Am I missing something here? This test question is from Sun and I'm doomed if I get a question of similar context in the SCJP exam.
Also, is this the main Sun mock exams (10 questions)?
[/B]
<B>~James Baud</B><P>He who asks, is a fool for five minutes;<BR>but, he who does not ask, remains a fool forever. (Chinese proverb)
Originally posted by James Baud:
Ooops, sorry 'bout the slip. What I meant was, option C would have been correct if "both" overriding and overridden getType() methods were static. Or, another option would be to call getType() in main() through a OverType object reference, ie [b]new OverType().getType(...). My point is, the program will not compile as it is, given option C.
Lam, try to compile the original code w/ option C and you'll see what I mean.
[/B]
<B>~James Baud</B><P>He who asks, is a fool for five minutes;<BR>but, he who does not ask, remains a fool forever. (Chinese proverb)