Next: Importing a package from another package, Previous: Moving a class into a sub-package, Up: Packages in J.T.W. and Java [Contents][Index]
When referring to a class or interface in a package you need to
specify the package name in front of every class name and interface
name in the package you want to access, like so, in the main folder
~/jtw-tutorials (outside of any package):
classBbeginbeginMainvarpkg.A a1 =newpkg.A(123); a1.meth1(); // prints out "meth1:123"varpkg.A a2 =newpkg.A(456); a2.meth2(); // prints out "meth2:456" pkg.A.func(); // prints out "func:666"endMainend
To avoid having to qualify each class name and interface name with
it’s package, you need to use the import directive like so before the
definition of the class like so:
importpkg.*;classBbeginbeginMainvarA a1 =newA(123); a1.meth1(); // prints out "meth1:123"varA a2 =newA(456); a2.meth2(); // prints out "meth2:456" A.func(); // prints out "func:666"endMainend