Using java packagename.*
//If you use package.* then all the classes and interfaces of this package will be accessible but not subpackages.
The import keyword is used to make the classes and interface of another package accessible to the current package.
//save by A.java
package pack;
public class A{
public void msg(){System.out.println("Hello");}
}
//save as B.java
package mypack;
import pack.*; //Importing the package named pack which contains class A.
class B{
public static void main(String args[]){
A obj = new A();
obj.msg();
}
}