1.

Data members ________________ (C++)(a) Can be initialized with declaration in classes(b) Can be initialized only with help of constructors(c) Can be initialized either in declaration or by constructor(d) Can’t be initializedI had been asked this question in an internship interview.The origin of the question is Data Members topic in section Class Members & Types of Object Oriented Programming

Answer»

The CORRECT choice is (b) Can be initialized only with help of constructors

The EXPLANATION: The data members are not property of class, those are property of the instances of the class. And the memory for the data members are not RESERVED until a CONSTRUCTOR is called. HENCE we use constructors for their initialization after the memory is reserved.



Discussion

No Comment Found

Related InterviewSolutions