Why no global variables in java like C++?

java

Solution

If you really want to do that, make it a public static variable.

However, you'd be advised to try not to - it makes for less elegant, harder to maintain, harder to test code.

Problem

Why there are no global variables in java? If I like to use any variable in all classes of a program then how can I do that?

Original source