Global variables in java
1 answer
Usually the default package is not used, your package will be something like com.yourdomain.mypackage
. As long as you declare a class as public
, it can be seen by all classes as long as they import it.
The class will look like
package com.mycompany.mypackage;
public class MyClass {...}
Then the user of the class will be
package com.mycompany.anotherpackage;
import com.mycompany.myPackage.MyClass;
private final MyClass myClass = new MyClass();
+6
a source to share