How and where to use Static modifier in Java?

前端 未结 7 2125
走了就别回头了
走了就别回头了 2020-11-28 10:43

How and where should we use a Static modifier for:

1. Field and
2. Method?

For example in java.lang.Math class, the fields

相关标签:
7条回答
  • 2020-11-28 11:38

    Usually when the method only depends on the function parameters and not on the internal state of the object it's a static method (with singletone being the only exception). I can't imagine where static fields are really used (they're the same as global variables which should be avoided).
    Like in your example the math functions only depend on the parameters.

    0 讨论(0)
提交回复
热议问题