global variables | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

global variables

like we got global variables in C language which can be operated throughout all user define functions, do we have any such thing in java that run in all the method of the class.?

10th Sep 2016, 5:20 PM
Monis Hasan Khan
Monis Hasan Khan - avatar
3 Answers
+ 1
Yes, define the variable outside of any methods. I believe the section on encapsulation covers this.
10th Sep 2016, 10:44 PM
Greg Sims
Greg Sims - avatar
+ 1
Define a static variable inside any class . Examples: public static int age; public static final String FILENAME="data.txt";
11th Sep 2016, 12:18 AM
Tiger
Tiger - avatar
0
wrong
20th Sep 2016, 11:18 AM
rahul gautam
rahul gautam - avatar