How to Define and Use Global Variable in Java


Here we will see the method to define and use global variable in Java.

Source Code

1) define global variable

package com.beginner.examples;

public class GlobalExample1 {

	public static final String CASE = "java"; // global
}

2) use global variable

package com.beginner.examples;

public class GlobalExample2 {

    public static void main(String[] args){
    	//get global variable.
    	System.out.println(GlobalExample1.CASE);
    }
}

Output:

java
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments