Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (11.4k points)

How do you define Global variables in Java?

1 Answer

0 votes
by (32.3k 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)
0 votes
1 answer
+1 vote
1 answer
asked Aug 1, 2019 in Java by Sammy (47.6k points)

Browse Categories

...