1.

If data members are private, what can we do to access them from the class object?(a) Create public member functions to access those data members(b) Create private member functions to access those data members(c) Create protected member functions to access those data members(d) Private data members can never be accessed from outside the classI have been asked this question in an interview.The question is from Encapsulation in portion OOPs Concept & Features of Object Oriented Programming

Answer»

Correct answer is (a) Create PUBLIC member functions to access those data members

Best EXPLANATION: We can define public member functions to access those private data members and get their value for use or ALTERATION. They can’t be ACCESSED directly but is possible to be access using member functions. This is done to ENSURE that the private data doesn’t get modified accidentally.



Discussion

No Comment Found

Related InterviewSolutions