+ 4
[DUPLICATE] Can someone explain why we use static?
3 Answers
+ 12
The static modifier tells the compiler that the corresponding member belongs to the class itself and not to instances of the class. This means that there will only be one copy of that member, no matter the amount of instances of the class which has been declared.
Please consider:
https://www.sololearn.com/discuss/946142/?ref=app
https://www.sololearn.com/discuss/916960/?ref=app
https://www.sololearn.com/discuss/703955/?ref=app
+ 9
https://www.sololearn.com/learn/Java/2159/
https://www.sololearn.com/learn/CSharp/2666/
+ 4
The static access modifier basically specifies that there can only be one instance of that thing at once, even if multiple classes have been created. In the case that that does happen, it will be the same throughout each class.
For example, say you have a class with a static variable x. When the class is first created, the value of x will be set. Whenever any other class is created, it will always have the same value as it was originally set to when the first class was created.
Hope this cleared that up!