0

I have been coding in Java for sometime and I understand the difference between Static and non static methods. But I recently came across static Object reference

 private static Work workTwo = new Work();

What is the need for a static object reference and under what case should I include them in my code

God_Father
  • 491
  • 3
  • 8
  • 17

1 Answers1

0

Use it when the semantics are what you need. Specifically when you want the value to exist only once and be shared across all instances of the class, or the entire application. static final is good for immutable constants (eg numbers or strings).

See also: Why are static variables considered evil?

dsh
  • 12,037
  • 3
  • 33
  • 51