Take FREE!! Online Cocubes Mock Test to Crack various Companies Written Exams.
Get Off-Campus Placement Jobs Info !!!
Take 30+ FREE!! Online Arithmetic Aptitude Mock test to crack any Exams.

Commvault Written Test Qs.(C++ Programming) :: Objects and Classes - Discussion

9 / 40

What is the output of the C++ program?

#include <iostream>
using namespace std;
class test { 
float x,  y; 
test(float a = 1.0,  float b = 2.0)
x = a;
y = b;

test operator + (test & obj) {
return test(this->x + obj.x,  y + obj.y);

operator float () {
return  (x + y) ;

int main () {
test obj1(1.23, 4.56), obj2;
obj2  = obj1 + obj2;
cout << obj2;
return 0;




DCompilation error: binary '<<': no operator found which takes a right-hand operand of type 'test'

Answer: Option (Login/Signup)

Show Explanation

Operator overloading can be defined as assigning new meaning to the overloaded operator. In our program, we overloaded '+' operator which gets called when two instances of type 'test' are added. 

operator float () is a conversion operator which converts type 'test' to float. 

Asked In :: Commvault Sopra Steria

Post Your Answer Here:     

Rate This: +0 -0

Report Error

Please Login First Click Here