Jeff Verdegan wrote:All the imports in a .java file have to go at the top of that file. The only thing that can come before them is the package statement and comments.
This is why the error message says, "class,interface or enum expected." Those are the only things that can appear where you've put that import statement.
Pay close attention to the error messages, they usually tell you exactly what's wrong, even if it's not immediately obvious at first glance what they're saying.
Ulf Dittmer wrote:Import statement must be at the beginning of a source file, not somewhere in the middle of it. Also note that Java is case-sensitive - there are a few compilation errors where you mixed up upper- and lowercase.
Campbell Ritchie wrote:You ought to use code tags, but I have added them for yoiu. Coloured text doesn’t work inside code tags. It looks a lot better () and would have been better still with correct indentation.
Is that example from Head First Java? Which page? Have you copied it correctly? I am sure Sierra & Bates would never use == true, and neither should you; it is poor style and error‑prone in case you write = by mistake.
The idea of the condition is to show that the bangbang‑a‑bang method is not called when that flag is set to false. In line 3 it becomes true, and later (line 15) it becomes false.