Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Bill Brogden's 1.4 Mock Question

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

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
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Michael Powers
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I understand but it compiles & runs under 1.4 & gives me a response of "Final alue 7". That's what I don't understand.
 
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Michael Powers
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

Try typing javac -version



Doh. I am running 1.5. No wonder...nevermind!

Thanks for helping to point out my bad oversight!

Michael
 
What are your superhero powers? Go ahead and try them on this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic