• Post Reply Bookmark Topic Watch Topic
  • New Topic

import and package inside class definition  RSS feed

 
N Sam
Ranch Hand
Posts: 77
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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

Henry
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!