0

I need to have certain info inside my program which I need to access and modify in between different classes inside different packages. I've tried using a separate class for them but it doesn't work because I need to make a new instance every time I use it in a different class.

Is there a way to solve this problem?

BRHSM
  • 782
  • 3
  • 12
  • 39

1 Answers1

4
public class ClassName {
    public static String varName = "this can be used globally;"
}

Now can be referenced globally by

ClassName.varName

Note: public is important since a private will not be accessible from the outside the class.

Kellen Stuart
  • 6,353
  • 5
  • 50
  • 73