Forums Register Login

import and package inside class definition

+Pie Number of slices to send: Send
I am puzzled by a note in the book I am reading (by Mala Gupta). Page 55 says "All java components you've heard of can be defined within a java class: import and package statements, variables.....". But the online oracle doc (tutorial) clearly says the following 2 statments:

"If present, package statement must be the very first line in a file"
"To import a specific member into the current file, put an import statement at the beginning of the file before any type definitions but after the package statement, if there is one. " (Here).

So, my question is, how can import and package be present inside a class ? (This seems to go against the 2 statements from oracle online tutorial).
+Pie Number of slices to send: Send
No, you cannot put import and package statements inside a class. If the book says literally that, then that's an error in the book.
+Pie Number of slices to send: Send

On the other hand, package and import statements doesn't define any Java components, which was mentioned in the book statement.

Henry
Why does your bag say "bombs"? The reason I ask is that my bag says "tiny ads" and it has stuff like this:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1556 times.
Similar Threads
packages and CLASSPATH
java package
default package
Confirmation on files without class or interface definitions
New to Java and trying to work with an existing app
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 14:20:16.