1.

Can data members be passed to a function using the object?(a) Yes, it can be passed only inside class functions(b) Yes, only if the data members are public and are being passed to a function outside the class(c) No, can’t be passed outside the class(d) No, can’t be doneThe question was posed to me in final exam.This intriguing question originated from Passing Object to Functions in division Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

The CORRECT choice is (B) Yes, only if the data members are public and are being passed to a function outside the CLASS

The best explanation: The data members can be passed with help of OBJECT but only if the member is public. The object will obviously be used outside the class. The object must have ACCESS to the data member so that its value or reference is used outside the class which is possible only if the member is public.



Discussion

No Comment Found

Related InterviewSolutions