2

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?

2
  • 1
    Very similar: stackoverflow.com/questions/2030148/… Commented May 10, 2010 at 16:48
  • 1
    good reference. worth noting that you can't import from the default package. Commented May 10, 2010 at 16:59

1 Answer 1

6

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();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.