declare a global variable in java
Code snippet on how to declare a global variable in java
public class SampleClass {
public static int max = 100;
}
This code creates a global variable called “max” with an integer value of 100. The keyword “public” means that the variable can be used by other classes. The keyword “static” means that the variable is created and available when the program starts and can be used without creating an instance of the class. The variable type is declared first, in this case it’s an integer. Finally, the variable name and value are declared. In this case, it’s max and 100.