Question: Given the following C + + class, what will be the output when the following main function is executed? class Box { int width, height;

Given the following C++ class, what will be the output when the following main function is executed?
class Box {
int width, height;
public:
Box(int w, int h) : width(w), height(h){}
int area(){ return width * height; }
};
int main(){
Box box1(3,4), box2(5,6);
cout << box1.area()+ box2.area();
return 0;
}
Given the following C++ class, what will be the output when the following main function is executed?
class Box {
int width, height;
public:
Box(int w, int h) : width(w), height(h){}
int area(){ return width * height; }
};
int main(){
Box box1(3,4), box2(5,6);
cout << box1.area()+ box2.area();
return 0;
}
Compilation Error
30
18
42

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!