Choose the correct option for the code given below. class A{ static int c=0; public: A(){ c++; } };

Sơn Lê

Member
Choose the correct option for the code given below.
class A{ static int c=0; public: A(){ c++; } };
A. Constructor will make c=1 for each object created
B. Constructor will make c=0 for each object created
C. Constructor will keep number of objects created
D. Constructor will just initialize c=0 then increment by 1
 
Answer: c
Explanation: The constructor is using a static member to keep the count of the number of objects created. This is done because the variable c is static and hence the value will be common for all the objects created.
 

Tìm kiếm

Back
Top