Why is static members called members of class? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why is static members called members of class?

13th May 2019, 1:39 PM
Yashita Namdeo
Yashita Namdeo - avatar
4 Answers
+ 10
HonFu are you trying to say that, if 2 instances of a class are trying to manipulate a static member data then they will be referring to the same memory So changes made by one object will get reflected on another object, ------------------- Another answer maybe: Because you don't require to refer a object to call/get a static data, just class name is enough.
13th May 2019, 2:12 PM
Aaditya Deshpande
Aaditya Deshpande - avatar
+ 3
Because they exist only once for the entire class instead of every instance having a version of its own.
13th May 2019, 2:03 PM
HonFu
HonFu - avatar
+ 3
HonFu nice code, I tried to do some thing with your code and boom..!! Now i have 2 Questions Q1) in the following code why that "in single quote" is not printing ? Q2) why its giving a complile time error when i added the 2nd GfG class..?? https://code.sololearn.com/cFO3ue8TtLKn/?ref=app https://code.sololearn.com/ckN1X69O6dk5/?ref=app Edit:i tried it newly the same way and worked.. https://code.sololearn.com/cyh9NegqVp8g/?ref=app
13th May 2019, 5:03 PM
Aaditya Deshpande
Aaditya Deshpande - avatar
+ 2
Aaditya Deshpande, yeah, that's what I said - in longer. 😉 Quick demo: https://code.sololearn.com/cjCt1i60VvLg/?ref=app
13th May 2019, 3:24 PM
HonFu
HonFu - avatar