0% found this document useful (0 votes)
16 views7 pages

C++ Module 3

This document discusses inheritance and polymorphism in C++. It contains questions and answers related to these object-oriented programming concepts like inheritance hierarchies, polymorphism via virtual functions, abstract classes, and more.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
16 views7 pages

C++ Module 3

This document discusses inheritance and polymorphism in C++. It contains questions and answers related to these object-oriented programming concepts like inheritance hierarchies, polymorphism via virtual functions, abstract classes, and more.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 7

Module 3

Inheritance & Polymorphism


1. The objects can directly access ?
a.Public members
b.Private members
c. Both of above
d. None of above
Answer: Option A

2. If new operator is used, then the constructor function is ?


A. Copy constructor
B. Default constructor
C. Static constructor
D. Dynamic constructor
Answer: Option D

3. The process of deriving a class from another derived class is known as ?


A. single inheritance
B. dual inheritance
C. multiple inheritance
D. multilevel inheritance
Answer: Option D

4. Which among following is not a valid visibility mode in c++ program ?


A. Private
B. Public
C. Protected
D. Limited
Answer: Option D

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.

7. Inheritance allow in C++ Program?


A. Class Re-usability
B. Creating a hierarchy of classes
C. Extendibility
D. All of the above
Ans : D
Explanation: Advantage of inheritance are like re-usability- it is possible to re-use existing class
in a new class that avoid re-writing same code and efforts. We can make an application easily
extensible.

8. Which of the following is not a type of Constructor?


a) Friend constructor
b) Copy constructor
c) Default constructor
d) Parameterized constructor

9. How many types of polymorphism are there in C++?


a) 1
b) 2
c) 3
d) 4

10. How run-time polymorphisms are implemented in C++?


a) Using Inheritance
b) Using Virtual functions
c) Using Templates
d) Using Inheritance and Virtual functions

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.

12. Which symbol is used to create multiple inheritance?


A. Dot
B. Comma
C. Dollar
D. None of the above
Explanation: For using multiple inheritance, simply specify each base class (just like in single
inheritance), separated by a comma.

13. Which of the following gets called when an object is being created?
A. Constuctor
B. Virtual Function
C. Destructors
D. Main

14.Destructor has a same name as the constructor and it is preceded by?


A. !
B. ?
C. ~
D. $
11. Like constructors, can there be more than one destructors in a class?
A. Yes
B. No
C. May Be
D. Can't Say

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

13. . Which of the following is true about constructors.


i) They cannot be virtual
ii) They cannot be private.
iii) They are automatically called by new operator.

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++.

17. How can we make a class abstract?


A. By declaring it abstract using the static keyword
B. By declaring it abstract using the virtual keyword.
C. By making at least one member function as pure virtual function
D. By making all member functions constant
Explanation: We can make a class abstract by making at least one member function as pure
virtual function.

18. How many specifiers are present in access specifiers in class?


A. 2
B. 1
C. 4
D. 3

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

21. Which of the following is true?


A. All objects of a class share all data members of class
B. Objects of a class do not share non-static members. Every object has its own copy
C. Objects of a class do not share codes of non-static methods, they have their own copy
D. None of these

22. Which of the following can be overloaded?


A. Object
B. Operators
C. Both A & B
D. None of the above

23. Which is also called as abstract class?


A. Virtual function
B. Derived class
C. Pure virtual function
D. None of the mentioned

24. What will be the output of the following program?

#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

25. What will be the output of the following program?


Note:Includes all required header files
class course
{ int x, y;
public:
course(int xx)
{
x = ++xx;
}
void Display()
{
cout<< --x << " ";
}
};
int main()
{
courseobj(20);
obj.Display();
int *p = (int*)&obj ;
*p = 5;
obj.Display();
return 0;
}
A. 20 4
B. 21 4
C. 20 5
D. 21 5

26. Correct way to declare pure virtual function in a C++ class is


A. Virtual void foo() =0 ;
B. Void virtual foo()= { 0 }
C. Virtual void foo() {} = 0;
D. None of the above

27. Which of the following in Object Oriented Programming is supported by Function


overloading and default arguments features of C++.
A. Inheritance
B. Polymorphism
C. Encapsulation
D. None of these

You might also like