views:

99

answers:

1

I want to make a class in java that is accessible to all other classes in my project.

I created this in the default package and now it cannot be seen. What is the best way to do this in java?

+6  A: 

Typically the default package is not used, your package would be something like com.yourdomain.mypackage. As long as you declare the class as public, it can be seen by all classes as long as they import it.

The class would look like

package com.mycompany.mypackage;

public class MyClass {...}

Then the user of the class would be

package com.mycompany.anotherpackage;
import com.mycompany.myPackage.MyClass;

private final MyClass myClass = new MyClass();
Jeff Storey