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 2 Question 36 Discussion

Actual exam question for C++ Institute's CPA-21-02 exam
Question #: 36
Topic #: 2
[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;

};

class B : public A {

string name;

public:

void set() {

y = 2;

z = 3;

}

void Print() { cout << y << z; }

};

int main () {

B b;

b.set();

b.Print();

return 0;

}

Show Suggested Answer Hide Answer
Suggested Answer: D

Contribute your Thoughts:

Stephen
2 days ago
The correct answer is C. The code will print 23 because the 'y' variable is protected and can be accessed by the derived class 'B', and the 'z' variable is public and can be accessed by any class.
upvoted 0 times
...
Bernadine
3 days ago
So the correct answer is C) It prints: 23. Got it!
upvoted 0 times
...
Adria
6 days ago
I agree with Alesia. The Print function will then output the values of y and z, which are 2 and 3 respectively.
upvoted 0 times
...
Alesia
7 days ago
I think it prints: 23 because the set function initializes y to 2 and z to 3.
upvoted 0 times
...

Save Cancel