I'm new here at the Javaranch forum (although I've been playing Rules Roundup for months). I'm scheduled to take my exam this coming Friday.
I have a couple of questions on some mock exam items that I have found frustrating:
Here's a question from Bill Brogden's 1.4 SCJP mock exam applet:
What happens when we compile and run code containing the following lines:
The choices are: (a) The code compiles and prints "Final value 7" when run. (b) The code compiles but generates a runtime exception in line 5. (c) The compiler balks at line 4.
I chose answer A (both on his site and in the Exam Cram book) and it's marked wrong. The correct answer is supposed to be C. I have written this code in a file and compiled it and it works fine. What am I missing?
Here is my code:
Also, one last question just to confirm what I've learned: Methods that override superclass methods cannot impose a greater (less general) visibility that the method being overridden (i.e. superclass method is declared public void go() but the overriding method is declared protected void go()). But overloaded methods are allowed to provide less visibility that the methods they overload?
So far, scored 79% on one of Bill's applet mock exams and a 67% on the Exam Cram exam 2. Scored a 70% on Marcus Green's mock exam. (All of these are ambiguous on the number of correct answers sometimes so I think I'm ready to roll this Friday!!)
Thanks for your help!
Michael
Tony Morris
Ranch Hand
Joined: Sep 24, 2003
Posts: 1608
posted
0
Which bit don't you understand exactly? Integer is a reference type; the + operator is not overloaded to take two reference operands, unless one is of type String. [ February 20, 2005: Message edited by: Tony Morris ]
I understand but it compiles & runs under 1.4 & gives me a response of "Final alue 7". That's what I don't understand.
Mike Gershman
Ranch Hand
Joined: Mar 13, 2004
Posts: 1272
posted
0
I have written this code in a file and compiled it and it works fine. What am I missing?
The mock exams are based on Java 1.4. It looks to me like you are using the Java 1.5.0 compiler and autoboxing is letting you add two Integer objects.
If you are taking the SCJP 5 beta, that's good. If you are taking SCKP 1.4, consider testing code with the Java 1.4.2 compiler.
Try typing javac -version
Methods that override superclass methods cannot impose a greater (less general) visibility that the method being overridden (i.e. superclass method is declared public void go() but the overriding method is declared protected void go()). But overloaded methods are allowed to provide less visibility that the methods they overload?
Correct, but "greater" visiblity is usually taken to mean "more general".
So far, scored 79% on one of Bill's applet mock exams and a 67% on the Exam Cram exam 2. Scored a 70% on Marcus Green's mock exam. (All of these are ambiguous on the number of correct answers sometimes so I think I'm ready to roll this Friday!!)
Suit yourself, but I would wait until I got over 90% on the mock exams.
Mike Gershman
SCJP 1.4, SCWCD in process
Michael Powers
Greenhorn
Joined: Feb 20, 2005
Posts: 6
posted
0
Originally posted by Mike Gershman:
The mock exams are based on Java 1.4. It looks to me like you are using the Java 1.5.0 compiler and autoboxing is letting you add two Integer objects.
If you are taking the SCJP 5 beta, that's good. If you are taking SCKP 1.4, consider testing code with the Java 1.4.2 compiler.