When we import a package using asterisk (*), all public classes are imported, we want not to import all the classes. In order to hide the classes inside the package, we need to declare those classes not as public.
Package package1;
Class A
{
.....
.....
}
public class B
{
.....
.....
}
import package1.*;
class C
{
public static void main(String args[])
{
public static void main(String args[])
{
A obj1=new A(); // this gives an error because it is not accessed
B obj2=new B(); // this is ok because it is public
}
}
