• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

OCA/OCP (Sybex) Ch.08 Question 35 Answer is irritating  RSS feed

 
Greenhorn
Posts: 11
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody,

again I have a slight Irritation About the given solution to that Question :

Question : In the following application, the values of street and City have been omitted. Which one of the following is a possible Output of executing this class?
I. 350 5th Ave - New York
II. Posted:350 5th Ave - New Yok



A. I only
B. II only
C. I and II
D. None of the above

-----------------
The Solution given in the Book is B

The Point here is, that inside the return Statement from getAddress inside the "" is a : written.

And a : is not a -
So, I am confused cause of that B, because I choosed None of the above is a possible Output, concerning the difference characters ":" and "-"

Is this just a typo Mistake or am I wrong in understanding the Question ?

Thanks again for enlighten me
 
Marshal
Posts: 64179
215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please supply full details of the book and page number. Please look here and here to see whether it has been reported before. It looks like a typo.
 
Ranch Hand
Posts: 3218
19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The other problem with that question is that as written here (without knowing what the original really says), what's an "output"?  We see a method that returns a String (which is not necessarily printed), and a finally block that prints something (but doesn't affect the return value).  Is an "output" what's returned, or what's printed?  Both?  Who knows?

If we assume that "output" means what's printed, and we assume that some code not shown is going to print the return value, and we replace ":" with "-" (or vice versa), then B would be correct.
 
Campbell Ritchie
Marshal
Posts: 64179
215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are only two “possible” outputs given in the question, so we have to assume something prints the value returned from the method.
OP Why is “350 5th Ave - New York Posted: ” not given?
 
Mike Simmons
Ranch Hand
Posts: 3218
19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, any time "none of the above" appears as an option, it's hard to be confident about making assumptions based on trying to make the answer match one of the other answers given.  We don't have to assume anything - the correct answer here (based on what's shown here) is "none of the above".  That may or may not be what the author intended - we're second guessing both (a) is it transcribed correctly, and (b) what did the author intend.  But "none of the above" could be the intended answer, and it has the added virtue of being correct, for what is shown here.

Also, if we assume something prints the value - is it something that prints after the method has returned?  Or could it be a print statement inserted into the method itself?  That can give different answers, including your last suggestion.
 
Campbell Ritchie
Marshal
Posts: 64179
215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mike Simmons wrote:. . . Or could it be a print statement inserted into the method itself? . . .

The one thing we do know is that there isn't an instruction to print the address in that method.
 
Mike Simmons
Ranch Hand
Posts: 3218
19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We also "know" that the method builds the address with a ":" rather than a "-".  And yet, we're willing to speculate on what the authors meant to write.  Or what the OP may have miscopied.  I don't think any of this is definite at this point - for all I know, the question in the book might actually have a print statement, which the OP misremembered as a return statement.  Or not.  

Assuming the question was copied directly, and therefore needs revision anyway... I do think that the question would be better if the ambiguity about what is "output" (print or return value) were removed.  Replacing the return with a print statement would make things clearer in that sense, if a correction is required.
 
Aleana Cologne
Greenhorn
Posts: 11
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mike Simmons wrote:We also "know" that the method builds the address with a ":" rather than a "-".  And yet, we're willing to speculate on what the authors meant to write.  Or what the OP may have miscopied.  I don't think any of this is definite at this point - for all I know, the question in the book might actually have a print statement, which the OP misremembered as a return statement.  Or not.  

Assuming the question was copied directly, and therefore needs revision anyway... I do think that the question would be better if the ambiguity about what is "output" (print or return value) were removed.  Replacing the return with a print statement would make things clearer in that sense, if a correction is required.



The Question is in Chapter 8 and Question 35  

And in the main Method is only this call:
 
Mike Simmons
Ranch Hand
Posts: 3218
19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, the question does resolve that ambiguity - thanks.  Further, while Campbell pointed you to errata earlier, he didn't include a link to the book you're actually using.  See Java OCA/OCP 8 Programmer Practice Tests errata.  You can find Ch. 8 q 35 listed there, with the fix.  So, this has already been noted and addressed.
 
Master Rancher
Posts: 3189
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But even then: since the finally is using a 'prinrtln(...)' the possible output should be split over 2 lines.    
 
Campbell Ritchie
Marshal
Posts: 64179
215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Piet Souris wrote:. . . the possible output should be split over 2 lines.    

So it is. Back to the errata page!
 
Mike Simmons
Ranch Hand
Posts: 3218
19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depending once again on what the original question in the book really says.  I know the actual exam used to routinely use System.out.print() rather than println() for questions like this, precisely to make it easier to show the output on one line.  Don't know if that was done in the book or not.
 
author & internet detective
Posts: 39244
727
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mike Simmons wrote:Depending once again on what the original question in the book really says.  I know the actual exam used to routinely use System.out.print() rather than println() for questions like this, precisely to make it easier to show the output on one line.  Don't know if that was done in the book or not.


We used printlns and didn't show the trailing line break in the answers. Although technically the next answer begins on the next line so...
 
Mike Simmons
Ranch Hand
Posts: 3218
19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Jeanne.  Here I don't think the concern is about the final line break (or lack thereof) - but whether there should be a line break between the "Posted:" and the address.  If println is used, there should be one -but the answer shown here (this thread) is

If that's what the book says, time for another errata.  Possibly for "New Yok" as well. ;) . Without the book handy, it's hard for us to know.  Cheers...
 
Jeanne Boyarsky
author & internet detective
Posts: 39244
727
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mike Simmons wrote:Thanks, Jeanne.  Here I don't think the concern is about the final line break (or lack thereof) - but whether there should be a line break between the "Posted:" and the address.  If println is used, there should be one -but the answer shown here (this thread) is

If that's what the book says, time for another errata.  Possibly for "New Yok" as well. ;) . Without the book handy, it's hard for us to know.  Cheers...


This suggests I should have looked at the book. The question does use print() and not println() in both places in this question.

We definitely tried to do that for questions like this!
 
no wonder he is so sad, he hasn't seen this tiny ad:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!