Is it possible in java to create variables which will be available between all classes?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
4 views
There are several variables(constants), and there are several classes. Variables are used in almost all classrooms. How to do that-if they were available in all classes without initialization?
by | 4 views

3 Answers

0 like 0 dislike
static variable
by
0 like 0 dislike
If constant, then:
public static final
If a variable, then:
public static
by
0 like 0 dislike
Generally, it is bad practice to use global variables in OOP, but if they cannot be avoided (and if it is constant), then in the same class or interface prescribed fields with the modifiers public static final, and then in all other classes there is a reference to these fields.
by
110,608 questions
257,186 answers
0 comments
28,015 users