Pergunta de entrevista da empresa Amadeus

9. Consider the following program #include <iostream.h> class Base{ protected: int a; public: void seta(int x) { a = x;}; void printa(void) {cout << a; }; }; class SecondClass : public Base { public: int b; }; void main (void) { Secondclass tmp; tmp.seta(12); tmp.printa(); } Which of the following is true? a. SecondClass.a is public b. SecondClass.a is private c. SecondClass.a is protected d. SecondClass.a is not accessible 10. Which of the following should be made private to prevent an object from being copied? a. copy constructor b. assignment operator c. both of the above d. both of the above and also the default constructor 11. Members of a class declared as protected are: a. accessible only by the compiler b. accessible only by the members of its own class c. accessible only by the members of its own class and classes inherited from it d. accessible by anything in the same scope as the class 12. Given the following code fragment, what output would be generated? int i; for (int i = 0; i < 4; ++ i); std::cout << i << std::endl; a. 0 b. 3 c. 4 d. undefined

Resposta da entrevista

Sigiloso

18 de jul. de 2013

#10 is unclear