//Demo.java
package pack;
public class Demo {
public void msg() {
System.out.println("Hello");
}
}
//Test.java
package mypack;
import pack.Demo;
class Test {
public static void main(String args[]) {
Demo obj = new Demo();
obj.msg();
}
}
import package.myclass;
Package can have many classes but sometimes we want to access only specific class in our program in that case, Java allows us to specify class name along with package name.
If we use import packagename.classname statement then only the class with name classname in the package will be available for use.