先放资料:
Learning a New Programming Language: Java for C++ Programmers
java package # 先说几条重要的人话:
一个 java 文件第一行可以声明该文件所属于的 package,package 的名字必须与整个工作目录的路径名相同。 同一个 package 下的 class 默认有互相访问的权限。 访问属性设置为 public 的 class,如果该 class 所在的 file 声明了 package,那么可以被其他 package 下的 class 访问到。 .java 的文件名必须与文件中设置为 public 的 class 名保持一致(如果没有 public 的类,那么名称任意)。 Every class is part of some package. All classes in a file are part of the same package. You can specify the package using a package declaration (package name;) as the first (non-comment) line in the file. Multiple files can specify the same package name. If no package is specified, the classes in the file go into a special unnamed package (the same unnamed package for all files). If package name is specified, the file must be in a subdirectory called name (i.e., the directory name must match the package name). You can access public classes in another (named) package using package-name.class-name. You can access the public fields and methods of such classes using package-name.class-name.field-or-method-name. You can avoid having to include the package-name using import package-name.*; or import package-name.class-name; at the beginning of the file (after the package declaration). The former imports all of the classes in the package, and the second imports just the named class. You must still use class-name to access the classes in the packages, and class-name.field-or-method-name to access the fields and methods of the class; the only thing you can leave off is the package name. 下面是一些例子: