Thursday 2 June 2016

Why JAVA does not support global variables ?



The answer is to your question is, because Java doesn't support global variables, by design. Java was designed with object-oriented principles in mind and as such, every variable in Java is either local or a member of a class.
Static class members are globally-accessible, which is certainly one possible definition of a global variable, depending upon your interpretation of the term. To be pedantic, while Static class members are accessible via the class name and therefore across multiple scopes, they are still class members; and therefore not truly global variables as such.
Java's lack of support for global variables is a good thing, as using global variables is a design anti-pattern.

No comments:

Post a Comment