I have reached while loop description which has the following example on page 77:
What confused me was that bitesOfCheese was never explicitly initialized, however still gets value of 5 assigned upon execution of eatCheese and therefore can legally participate in while expression check.
Could you please explain why does it automatically gets assigned the value of 5?
You need to have a look at the rest of the code which you haven't posted here. bitesOfCheese is a parameter so I guess the value of 5 was passed to this method.
Please provide more details of the book, including author. Is that Boyarsky and Selikoff? I don't have a copy of that book.
I suggest you go through the code first and indent it correctly. People who write cert exam practice questions sometimes indent their code inconsistently to make the question harder. Did you notice that bitesOfCheese is a method parameter in line 2? Is the final output 5? In that case there must be some code calling eatCheese(10); Such a method call definitely assigns a value to that parameter.
Because those who mind don't matter and those who matter don't mind - Seuss. Tiny ad:
Gift giving made easy with the permaculture playing cards