0 votes
1 view
in Java by (11.5k points)

How do you define Global variables in Java?

1 Answer

0 votes
by (31.4k points)

 You can make use of static Keyword in order to define Global Variable

public class Example {

    public static int a;

    public static int b;

}

Now, you are free to access a and b from anywhere. Just call:

Example.a;

Example.b;

Related questions

0 votes
1 answer
asked Sep 19, 2019 in Java by Anvi (10.2k points)
+11 votes
2 answers
asked May 26, 2019 in Java by stevie65 (900 points)
+1 vote
1 answer
asked Aug 1, 2019 in Java by Sammy (47.8k points)
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...