+ 2

Why declare a static variable

the word "static" allows a method to execute without having to create an instance of the class that contains it. What about a variable declare static ... ?? in which case did you declare a static variable ?? is there any disadvantage

31st Aug 2019, 4:43 PM
jurise mboumene
jurise mboumene - avatar
3 odpowiedzi
31st Aug 2019, 5:49 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 5
To maintain data relevant to the whole range of objects within a class and not just relevant to a single object.
31st Aug 2019, 10:49 PM
Sonic
Sonic - avatar
0
thank you very much for all your answers they helped me a lot...... if I understand correctly a static variable is specific to the class. Thus, if multiple objects are instantiated from any class, relative to the instance variables. which they can be different from one object to another, the static variables will be the same for all the objects of this class from where the interest to declare them static ...
1st Sep 2019, 9:41 PM
jurise mboumene
jurise mboumene - avatar