This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi Gaelle, is size declared before the Wheel constructor is invoked? In that case it shouldnt be a problem you agree? Can you please post the entire program for my understanding. Is it from K & B SCJP 6?
Joined: Mar 24, 2011
yes it is this same exam practice book:
Joined: May 12, 2011
Gaelle, I tried it
I am getting the following errors:
The declaration int size is missing in Bicycle. Where does it occur?
I looked thru the pdf version of the book but was not able to find this problem. Can you tell me the chapter/page number. thanks
Shuba, your definition of the "Wheel" class is just missing the declaration of "size" which appears at the bottom of the class, as shown in the first post above; that's the whole point of this thread. All the other stuff you've posted, including your initial request for more code, is just a distraction and is not relevant, so let's just try to stick to the actual question, shall we?
Gaelle, the fact is simply that when the code inside a method or constructor body is compiled, all the members of that class are in scope. They don't need to be forward declared; it's perfectly OK -- and rather common -- for a method to refer to a variable or method which is declared later on in the same class.