1. Home
  2. Computer Science MCQs
  3. C++ and Object-Oriented Programming
  4. How many copies of a static data member exist for a C++…

Added 30 Nov -0001

How many copies of a static data member exist for a C++ class with several objects instantiated?

  1. One per object, created with each constructor
  2. One per translation unit that includes the header
  3. One per derived class that inherits it
  4. Exactly one, shared by every object of the class Correct answer

Correct answer

D. Exactly one, shared by every object of the class

13 views

MCQSEXAM

Explanation

A static data member belongs to the class rather than to any instance, so all objects share a single copy, which is ideal for counters and configuration shared across instances. Before C++17 it also needed a separate out-of-class definition, which is why headers often pair a declaration with a definition in one source file. Its static member function counterpart can be called without any object and has no this pointer.

Reference

Asked in: NTS, PPSC IT, Campus Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is D? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More C++ and Object-Oriented Programming MCQs

Practise all C++ and Object-Oriented Programming MCQs

Similar MCQs