C++ Module 3
C++ Module 3
5. When the inheritance is private, the private methods in base class are __________ in the
derived class.
A. Inaccessible
B. Accessible
C. Protected
D. Public
Ans : A
Explanation: When the inheritance is private, the private methods in base class are inaccessible
in the derived class.
6. What is meant by multiple inheritance?
A. Deriving a base class from derived class
B. Deriving a derived class from base class
C. Deriving a derived class from more than one base class
D. None of the mentioned
Ans : C
Explanation: Multiple inheritance enables a derived class to inherit members from more than
one parent.
11. . Can we pass parameters to base class constructor though derived class or derived class
constructor?
A. Yes
B. No
C. May Be
D. Can't Say
12. What will be the output of the following program?
Note:Includes all required header files
class find {
public:
void print() { cout<<" In find"; }
};
class course : public find {
public:
void print() { cout<<" In course"; }
};
class tech: public course { };
int main(void)
{ tech t;
t.print();
return 0;
}
A.In find
B. In course
C. Compiler Error: Ambiguous call to print()
D. None of the above
Explanation: The print function is not present in class tech. So it is looked up in the inheritance
hierarchy. print() is present in both classes find and course, which of them should be called?
The idea is, if there is multilevel inheritance, then function is linearly searched up in the
inheritance hierarchy until a matching function is found.
13. Which of the following gets called when an object is being created?
A. Constuctor
B. Virtual Function
C. Destructors
D. Main
12. State whether the following statements about the constructor are True or False.
i) constructors should be declared in the private section.
ii) constructors are invoked automatically when the objects are created.
A. True,True
B. True,False
C. False,True
D. False,False
A. All i,ii,iii
B. i& iii
C. ii & iii
D. i& ii
14. Destructors __________ for automatic objects if the program terminates with a call to
function exit or function abort
A. Are called
B. Are not called
C. Are inherited
D. Are created
15. Which contructor function is designed to copy object of same class type?
A. Copy constructor
B. Create constructor
C. Object constructor
D. Dynamic constructor
Explanation: Copy constructor function is designed to copy object of same class type.
16. Explanation: Copy constructor function is designed to copy object of same class type.
50. Which of the following is not correct for virtual function in C++ ?.
A. Virtual function can be static.
B. Virtual function should be accessed using pointers
C. Virtual function is defined in base class
D. Must be declared in public section of class
Explanation: Virtual function is can’t be static in C++.
19. Which of these following members are not accessed by using direct member access
operator?
A. Public
B. Private
C. Protected
D. Both B & C
20. Which other keywords are also used to declare the class other than class?
A. Struct
B. Union
C. Object
D. Both struct& union
#include <iostream>
using namespace std;
class LFC
{
static int x;
public:
static void Set(int xx)
{
x = xx;
}
void Display()
{
cout<< x ;
}
};
int LFC::x = 0;
int main()
{
LFC::Set(33);
LFC::Display();
return 0;
}
A. The program will print the output 0.
B. The program will print the output 33.
C. The program will print the output Garbage.
D. The program will report compile time error.
Explanation: The program will report compile time error: cannot call member function "void
LFC::Display()" without object