1.

If a class have two data members and two functions to add those two numbers and to subtract them, which among the following is most efficient if the programmer wants to implement multiplication too?(a) Define a public function which multiplies two numbers(b) Define a public function that returns values of two data members(c) Define a private function which multiplies two numbers(d) Define a private function that returns values of two data membersI have been asked this question in a national level competition.The question is from Class Use in section Classes of Object Oriented Programming

Answer»

The correct option is (b) Define a public function that RETURNS values of two data MEMBERS

Easy explanation - The best choice would be to define a public member function that returns the values of two data members of the class. This WAY we can implement any operation on those data members. Also there won’t be any need to MODIFY the program and to add NEW functions for each new operation.



Discussion

No Comment Found

Related InterviewSolutions