Subscribe

RSS Feed (xml)

Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger

Monday, November 19, 2007

java Package declarations

Each file may have a package declaration which precedes all non-comment code. The package name must be the same as the enclosing directory.

Default package. If a package declaration is omitted, all classes in that directory are said to belong to the "default" package.

Here are two files in the packagetest directory.

package packagetest;

class ClassA {
public static void main(String[] args) {
ClassB.greet();
}
}
and
package packagetest;  // Same as in previous file.

class ClassB {
static void greet() {
System.out.println("Hi");
}
}

Note that these source files must be named ClassA.java and ClassB.java (case matters) and they must be in a directory named packagetest.

No comments:

Post a Comment

Archives