I'm having trouble understanding the answer to review question 6 in chapter 1 of the book.
Can someone tell me where my thinking is going wrong.
I thought the code would not compile because you have
and according to the "Ordering Elements in a Class" section of chapter 1, Table 1.4 this is not allowed. Packages must be the first statements in the code if they are present. How then can you have a package after a class? Or am I not getting it right?
The correct answer in the book is E.
I thought it was F.
6. Given the following classes, what is the maximum number of imports that can be removed and have the code still compile?
F. Does not compile.
When I try compiling the code with:
I get the following errors. (I get similar errors if I try compiling with javac Tank.java, I'm not sure which one I should be doing)
And Jeanne and/or Scott if you happen to come across this post and aren't happy about me posting this question from your book, please tell me. I'm thinking I'll be asking quite quite a few questions in the coming weeks, so I'll refrain from doing it again.
posted 2 years ago
Actually, now that I think of it. I had the same confusion with review question 5.
The package, import and class aren't in the order they're supposed to be according to table 1.4.
Am I being daft?
In the printed copy of the book, there is a line break before each package statement. This is intended to show that each is defined in a separate file. I checked the electronic version of the book and these line breaks are missing. You can assume when this happens that each package statement is intended to be in a separate file.
I've added this to our errata and credited you with reporting it. This kind of issue is hard to prevent because it was right, when we wrote it, in all the page proofs we reviewed and in the printed book.
And it's fine to post questions from the book as long as you aren't posting all of them . Before posting, check the errata to confirm it hasn't been reported already. If it is still not clear, it is fine to ask (ideally by replying to that thread).
Tom Keegan wrote:Is that right?
And something similar for questions 5 and 7?
Just a little (useful) tip: if you want to simulate different (seperate) source code files, you can use multiple code-tags, one for every source code file. For each source code file line numbering will start at 1. And if required you can add at the top a comment with the name of the source code file as well. So let's apply this tip to the code snippet and you'll get