mypackage.HelloWorld helloworld = new mypackage.HelloWorld();
import"
keyword: For example,| import world.*; // we can call any public classes inside the mypackage package |
Lets see an example importing the created package into the another program file.
package importpackage;
|
In this program the package "importpackage"
is created under the "c:\nisha" directory that will be imported into another program file to call the function
of the class "HelloWorld".
Now make a program file named "CallPackage" under the "c:\nisha"
directory importing the
package "importpackage".
import importpackage.*;
|
Out of the program:
| C:\nisha\importpackage>javac *.java C:\nisha\importpackage>cd.. C:\nisha>javac CallPackage.java C:\nisha>java CallPackage This is the function of the class HelloWorld!! |
Make sure to the directory structure for this program shown as:

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: How to import a package View All Comments
Post your Comment