1.

Which among the following is true for data members?(a) Private data members can be initialized with declaration in class(b) Static members are initialized in constructors(c) Protected data members can be initialized in class directly(d) Static data members are defined outside class, not in constructorThis question was posed to me in an interview for job.My doubt stems from Data Members topic in division Class Members & Types of Object Oriented Programming

Answer»

The CORRECT choice is (d) Static data MEMBERS are DEFINED outside class, not in constructor

The best explanation: Static members are not property of instances of classes. Those are shared by all the object of classes. HENCE those are defined outside the constructor, so as to make them COMMON for all the objects.



Discussion

No Comment Found

Related InterviewSolutions