Free CPA-21-02 Exam Braindumps (page: 15)

Page 15 of 65

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

#include <iostream>
#include <string>
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;

  1. set();
  2. Print();
    return 0;
    }
  3. It prints: 123
  4. It prints: 000
  5. It prints: 23
  6. It prints: 12

Answer(s): C



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

#include <iostream>

using namespace std;

class A
{
public:
void Print(){ cout<<"A";}
};
class B:public A

{
public:
void Print(){ cout<< "B";}
};
int main()
{
A *obj;
A ob1;
obj = &ob1;
obj?>Print();
B ob2;
obj = &ob2;

obj?>Print();
}

  1. It prints: AB
  2. It prints: AA
  3. It prints: BA
  4. It prints: BB

Answer(s): B



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

#include <iostream>
#include <string>
using namespace std;

class A {
protected:
int y;
public:
int x;
int z;
A() { x=2; y=2; z=3; }
A(int a, int b) : x(a), y(b) { z = x ? y;}
void Print() {
cout << z;
}
};

int main () {
A a(2,5);

  1. Print();
    return 0;
    }
  2. It prints: ?3
  3. It prints: 2
  4. It prints: 6
  5. It prints: 5

Answer(s): A



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

#include <iostream>

using namespace std;

void fun(int*);

int main()
{
int i=2;
fun(&i);
cout<<i;
return 0;
}

void fun(int *i)
{
*i = *i**i;
}

  1. It prints: 1
  2. It prints: 4
  3. It prints: 10
  4. It prints: 0

Answer(s): B



Page 15 of 65



Post your Comments and Discuss C++ Institute CPA-21-02 exam with other Community members:

Subash commented on October 21, 2024
I am planning to take this exam. Are these 257 questions enough to clear it? Also, does each section have a passing percentage, or is it based on the overall ?
INDIA
upvote