7.
MathWorks technical mcq question, verified with a worked answer. Free to practise - no sign-up.
(Prog. Concept Question) Static Keyword**
How many copies of a class static member are shared between all objects of the class?
Pick ONE option
Show answer & explanation
Static members exist exactly once per class, not per object instance. All objects of the class share the single copy stored in class memory (static storage duration), regardless of how many instances are created. Options B, C, and D misrepresent this fundamental behavior—static members are allocated when the class is loaded, not when objects are instantiated.
Step-by-step Derivation:
Static members in C++, Java, and most OOP languages are class-level variables, not instance-level. When you declare a static member, memory is allocated once for the entire class. All instances access this same memory location. For example: class MyClass { static int count; }; // ONE copy of 'count' exists, shared by all MyClass objects.