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

Page 26 of 65

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:
virtual 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>

using namespace std;

int main()
{
const int x=0;
const int *ptr;
ptr = &x;
cout<<*ptr;
return 0;
}

  1. It prints: 0
  2. It prints address of x
  3. It prints: 1
  4. Compilation error

Answer(s): A



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

#include <iostream>
using namespace std;

int main(){
int i = 1;
for(i=10; i>-1; i/=2) {
if(!i)
break;
}
cout << i;
return 0;
}

  1. It prints: 0
  2. It prints: 1
  3. It prints: -1
  4. Compilation error

Answer(s): A



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

#include <iostream>

#include <string>
using namespace std;

class A {
public:
int x;
A() { x=0;}
};
class B {
public:
int x;

B() { x=1;}
};
class C :public A, public B {
public:
int x;
C(int x) {
this?>x = x;
A::x = x + 1;
}
void Print() { cout << x << A::x << B::x; }
};
int main () {
C c2(1);
c2.Print();
return 0;
}

  1. It prints: 1
  2. It prints: 121
  3. It prints: 111
  4. It prints: 2

Answer(s): B



Page 26 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