Your code won't compile as is since you forgot to return an int from your initMainGuests method. hen you do return an int from that method the code will compile and run, but the result in my opinion is a bit surprising. Try running your code slightly modified so that it compiles and I changed a few of the printlns:
The best thing to do is to edit your initial post using the icon that looks like a piece of paper with pencil.
No, the use of occupancyPerRoom in the method does not violate the declare before read rule. But using the method where you do will not print the results that you may expect. The value of occupancyPerRoom printed and used in the calculation will be 0 and not 2. (You will have to give the method something to return to get it to compile).
I read that the declaration before read rule (DBRR) should not be violated. So as per that, the declaration can happen in the left hand side but not on the right hand side (RHS). But in the above code the method is on the RHS which very well violated the DBRR. Please anyone?
Regards, Jothi Shankar Kumar. S
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
That's just a call of the method. The compiler does not see the call to the method and then go to see what the method does.
The code referencing the instance variables is in the definition of the method. At the time the method body is compiled all the instance variables have been defined (even if not fully initialized). [ October 14, 2006: Message edited by: Barry Gaunt ]