It's not a secret anymore!
The moose likes Beginning Java and the fly likes return - problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "return - problem" Watch "return - problem" New topic

return - problem

John Frank

Joined: Jun 28, 2006
Posts: 4
sorry to bother again, but i dont get it.

In the maybeNew class, there are 2 returns (they are not seperated with a else).

The example before was clear but i ll explain (just to be sure)

Lets say giveSecret was 5, so the return 42 makes the value 42 now.
Back to the other code. Where do the returns go? -> maybeNew = 0?
But why are there 2 returns. Does the compilier make the value first 1 and then 0? Isnt it useless to use 2 returns or just for the example?
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

If the first return is executed, then the method is all done. No other code in the method is executed (including, of course, that second return.)

This code is quite odd -- there are all kinds of things that I'm sure you didn't intend here. You should probably ask for more help understanding what's going on.

One important thing I'll get you started on: after this code, the array m4a will contain 20 Mix4a objects. Every one of them will have a "counter" member equal to 1. Can you explain why?

[Jess in Action][AskingGoodQuestions]
marc weber

Joined: Aug 31, 2004
Posts: 11343

This might be easier to see with proper indentation...

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
John Frank

Joined: Jun 28, 2006
Posts: 4
oh....didnt know the thing, thought there must be an "else".

well this is an example from chapter 4 "Head first Java". Guess it should show the "return" ^^ . The container "thing" was explained before. thanks!
[ July 03, 2006: Message edited by: John Frank ]
I agree. Here's the link:
subject: return - problem
jQuery in Action, 3rd edition