How can we define global variables in java?

513    Asked by MarieBroadber in Java , Asked on Jul 26, 2021

I want to call the variables from anywhere, for which I need to declare them as global. But don’t know how to declare global variables in java ?

Answered by Julian Springer

To make global variables in java , you can use the keyword static:

public class Global

{
    public static int x;
    public static int y;
}

Your Answer

Interviews

Parent Categories