CLA-CPA Certified Questions

Q1.- What is the output of the following program?

    1. #include 
      using namespace std;
      int main(void) {
       int i = 1, j = 2;
       if(i > j && j > i)
       i++;
       if(i > j || j > i)
       j++;
       if(i | j)
       i++;
       if(i & j)
       j++;
       cout << i * j << endl;
       return 0;
      }
      
      
    2. 1. 2
    3. 2. 8
    4. 3. 3
    5. 4. 6

2

Q2.- What is the output of the following program?

    1. #include 
      using namespace std;
      struct A {
       int a;
       float b;
      };
      struct B {
       int b;
       float a;
      };
      struct C {
       A a; B b;
      };
      int main(void) {
       C c1 = {1, 2, 3, 4}, c2 = {5, 6, 7, 8};
       cout << c1.b.a + c2.a.b << endl;
       return 0;
      }
      
      
      
    2. 1. 6
    3. 2. 8
    4. 3. 10
    5. 4. 12

3

Q3.- What is the output of the following program?

    1. #include 
      using namespace std;
      class A {
      public:
       int x;
       void d() { x /= 2; }
      };
      class B : public A {
      public:
       int y;
       void d() { A::d(); }
      };
      int main(void) {
       B b;
       b.x = b.y = 4;
       b.d();
       cout << b.y / b.x << endl;
       return 0;
      }
      
      
    2. 1. This code may throw an InterruptedException
    3. 2. This code may throw an IllegalStateException
    4. 3. This code may throw a TimeOutException
    5. 4. Reversing the ofrer of o.wait() and o.notify() will cause this method to complete

1

Q4.- What is true? (Choose three)

    1. #include 
      using namespace std;
      int fun1(int p) {
       ++p;
       return p++;
      }
      int fun2(int &p) {
       ++p;
       return p++;
      }
      int main(void) {
       int a = 1, b, c;
       b = fun1(a);
       c = fun2(b);
       cout << a + b + c << endl;
       return 0;
      }
      
      
    2. 1. 4
    3. 2. 8
    4. 3. 6
    5. 4. 10

2

Q5.- What is the output of the following program?

    1.               class Vehicle {
          public void printSound() {
              System.out.print("vehicle");
              }
          }
      
      class Car extends Vehicle {
          public void printSound() {
              System.out.print("car");
          }
       }
      
      class Bike extends Vehicle {
          public void printSound() {
              System.out.print("bike");
          }
      }
      
      public class Test {
          public static void main(String[] args) {
              Vehicle v = new Car();
              Car c = (Car) v;
              v.printSound();
              c.printSound();
          }   
      }
      
      
    2. 1. 1
    3. 2. 2
    4. 3. 3
    5. 4. 4

4

Q6.- What is the output of the following program?

    1.  #include 
      using namespace std;
      char f1(char c) {
       return c == 'z' ? 'a' : c + 1;
      }
      char f2(char &c) {
       c = f1(c);
       return c;
      }
      int main(void) {
       char x = 'x';
       cout << f2(x);
       cout << f2(x);
       cout << f2(x) << endl;
       return 0;
      }
    2. ,XYZ, ,yza, ,xyz, ,YZA,
    3. 1. XYZ
    4. 2. yza
    5. 3. xyz
    6. 4. YZA

2