I am a bare-metal C, micro-controller guy who is now delving into OOP domain, starting with C# and C++.
- I understood that, for a member of one class to be accessible by another it has to be of the storage class static and access specifier should be public.
- Also, I am able to access public static variable of class2 (initialized with lets say 100), from class1 without creating an object/instance of class 2.
- But to access a non-static member public member of the same class one has to instantiate.
Now Questions:
- Why we can access a public static variable even when a class is not instantiated ?
- Do static variables share the same memory space (in other words are they not different) for two different objects/instances of the same class ?