Is there a way for a class in a package to access a class that is not in a package (i.e., those that are in the unnamed, default package)?

Andre van Dalen

Yes, you can do that by importing the class:

package MyPackage;
import RootClass;
public class MyClass
{
	public static void main(String[] argv)
	{
		RootClass obj = new RootClass();
		System.out.println(obj.toString());
	}
}

Just make sure that the class with no package is a public class so classes outside of the empty package can access it.

0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact