Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

C++ Institute Exam CPA-21-02 Topic 7 Question 38 Discussion

Actual exam question for C++ Institute's CPA-21-02 exam
Question #: 38
Topic #: 7
[All CPA-21-02 Questions]

What happens when you attempt to compile and run the following code?

#include

#include

using namespace std;

class A {

int x;

protected:

int y;

public:

int z;

A() { x=1; y=2; z=3; }

};

class B : public A {

string z;

public:

void set() {

y = 4;

z = "John";

}

void Print() {

cout << y << z;

}

};

int main () {

B b;

b.set();

b.Print();

return 0;

}

Show Suggested Answer Hide Answer
Suggested Answer: A

Contribute your Thoughts:

Eleni
2 days ago
But doesn't the set() function in class B change the value of y to 4 before printing?
upvoted 0 times
...
Reynalda
6 days ago
I disagree, I believe the answer is B) It prints: 2John.
upvoted 0 times
...
Eleni
7 days ago
I think the answer is A) It prints: 4John.
upvoted 0 times
...

Save Cancel