If only one memory location is to be reserved for a class variable, no matter…

2014

If only one memory location is to be reserved for a class variable, no matter how many objects are instantiated, then the variable should be declared as 

  1. A.

    extern

  2. B.

    static

  3. C.

    volatile

  4. D.

    const

Attempted by 212 students.

Show answer & explanation

Correct answer: B

A static variable is associated with the class itself rather than individual instances. This ensures that only one memory location is allocated for the variable, which is shared by all objects created from that class.

Explore the full course: Isro