A
A
Anton2018-06-28 09:31:44
Java
Anton, 2018-06-28 09:31:44

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

There are several variables (constants), and there are several classes. Variables are used in almost all classes. How to make them available to all classes without initialization?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
davidnum95, 2018-06-28
@Anton238

static variable

N
Nikita, 2018-06-28
@vasilek-nik

If constant, then:
If variable, then:
public static

M
MaxLich, 2018-06-28
@MaxLich

In general, it is bad practice to use global variables in OOP, but if you cannot do without them (and if they are constants), then fields with public static final modifiers are written in one class or interface, and then in all other classes these fields are accessed .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question