[JAVA rookie] ask questions about JAVA import package

questions are as follows:

clipboard.png

Option B, which says that a JAVA source file can have multiple package declaration statements, is wrong. A little do not understand, a class can import a lot of packages, why only 1 declaration statement?

Apr.02,2021

package declaration, not package import.


The

package import declaration indicates that the java class needs to reference other classes, and a java class may reference multiple other classes, which may be in different packages and require multiple package declaration imports.

package declaration is a namespace, reflecting that the file system is a directory hierarchy, the same java source file can only have one package declaration, and the same java source file can only be in one directory.

if you think about it, if you can have multiple package declarations, this is equivalent to the same java source file can be in different directories. How is that possible?

Menu