1.

If a const object calls a non-const member function then ____________________(a) Run time error may get produced(b) Compile time error may get produced(c) Either compile time or run time error is produced(d) The program can’t be compiledThe question was asked in an online interview.This key question is from Constant Member Functions in chapter Member Functions & its Types of Object Oriented Programming

Answer»

Right OPTION is (b) Compile TIME error may get PRODUCED

Easiest explanation - The program gets compiled but produces an error. The error is produced because a constant value is being CHANGED. Even if there is no code that can change any object value, but non-const MEMBER functions are assumed to change the values.



Discussion

No Comment Found

Related InterviewSolutions