Problem in initialising global variable

while initialising a global variable o as
int o=222;
I was getting error when I was using that in demo globalscopes.
it said rename it as static int o=222; at the top.
and doing this made error disappear.
what was the reason.
please explain.

When a variable is declared as static, then a single copy of the variable is created and shared among all objects at a class level. Static variables are, essentially, global variables. All instances of the class share the same static variable. so you need to state static

1 Like

and it will be necessary to use static all the time for initialising global variable?any limitations/cases?