Search code examples
javaprivatepublicprotected

Best access modifier for MODULE variable in any class file in java?


Ok, let me start it with the following example to get a brief example

public class ClassA{
______ static final String MODULE = "[ClassA]";
}

in the blank space, I came across many code snippet it has some times public or protected or private but could not understand the which one is the best and why?.I know protected is best for subclass implementation but then subclass to has MODULE variable.

basically MODULE is used in logging activities like for example

System.out.println(MODULE+"given message");

in-short which is best way to use for accessing?


Solution

  • Basically MODULE is used in logging activities...

    Then I would suggest to make it private, because it will not be used outside the class (assuming that other classes have similar static constants).