1.

What does a virtual function ensure for an object, among the following?(a) Correct method is called, regardless of the class defining it(b) Correct method is called, regardless of the object being called(c) Correct method is called, regardless of the type of reference used for function call(d) Correct method is called, regardless of the type of function being called by objectsThe question was posed to me in an online interview.This intriguing question originated from Virtual Functions in portion Member Functions & its Types of Object Oriented Programming

Answer»

The correct choice is (c) Correct method is called, regardless of the type of reference used for FUNCTION call

Best explanation: It is PROPERTY of the virtual function and one of their main use. Its use ensure that the correct method is called even though it is been called from different POINTER or REFERENCES. This also decreases chance of mistakes in PROGRAM.



Discussion

No Comment Found

Related InterviewSolutions