0% found this document useful (0 votes)
43 views2 pages

QUIZ III SET 1 Solution

Uploaded by

tanuja.it
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views2 pages

QUIZ III SET 1 Solution

Uploaded by

tanuja.it
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

QUIZ III

Name Course Title Object Oriented Programming Concepts


Roll No Course Code ITDC0201

Duration: 15 Minutes Total Marks: 5 Marks Date: 26 November, 2024


Each question carries 0.25 marks.

1. Which of the following is valid when accessing a base class function from a derived class?
a) baseFunc(); b) Base::baseFunc();
c) this->baseFunc(); d) All of the above

2. What is true about visibility modes in inheritance?


a) A protected member of the base class becomes public in the derived class under public inheritance.
b) A public member of the base class becomes private in the derived class under private inheritance.
c) A protected member of the base class becomes private in the derived class under private inheritance.
d) Both b and c

3. Which of these is incorrect about virtual functions?


a) They allow runtime polymorphism.
b) They are resolved using vtable and vptr.
c) They can be static.
d) A class with virtual functions requires a virtual table at runtime.

4. What will happen in the following code?


class A {
public:
void func() {} };
class B : public A {
public:
void func(int) {} };
B obj; obj.func();
a) Calls A::func() b) Calls B::func(int)
c) Compilation error d) Runtime error

5. Which of the following is true for an abstract class?


a) It must contain only pure virtual functions.
b) It can have both pure virtual and normal functions.
c) It can only be inherited privately.
d) It cannot have a destructor.

6. If A is a base class and B is a derived class, which of the following is valid?


a) A obj = B(); b) B obj = A();
c) A* ptr; B obj; ptr = &obj; d) Both a and c

7. Which statement is true about pointers to derived class objects?


a) A derived class pointer can always point to a base class object.
b) A base class pointer can always point to a derived class object.
c) Virtual functions are required for pointers to derived objects.
d) Both b and c

8. Which of these statements is correct about pure virtual functions?


a) They have a body by default.
b) They are defined using the keyword pure.
c) They are used to enforce function implementation in derived classes.
d) They can only exist in base classes with no constructors.
9. In private inheritance, protected members of the base class become _______________ in the derived class.
Answer: private
10. The keyword used to create runtime polymorphism is _______________.
Answer: virtual
11. A company has a base class Employee with functions to calculate basic pay. The Manager and
Technician classes derive from Employee and add specific functions for bonuses. If a Manager object
calls a function defined in Employee, what mechanism ensures the base class function is executed
correctly?
a) Function overriding
b) Function overloading
c) Polymorphism through virtual functions
d) None of the above

12. A class Shape is inherited by both 2DShape and 3DShape, and 2DShape is further inherited by Rectangle.
This represents _______________ inheritance.
Answer: hybrid
13. A _______________ function in a base class ensures that the derived class's function is executed at runtime
through a base class pointer.
Answer: virtual
14. Which type of inheritance is necessary for achieving polymorphism in C++.
a) Single b) Multiple
c) Multilevel d) Heirarchical
15. If same message is passed to objects of several different classes and all of those can respond in a different
way, what is this feature called?
a) Inheritance b) Overloading
c) Polymorphism d) Overriding

16. Which among the following is not true for polymorphism?


a) It is feature of OOP
b) Ease in readability of program
c) Helps in redefining the same functionality
d) Increases overhead of function definition always

17. Which concept will result in derived class with more features (consider maximum 3 classes)?
a) Single inheritance
b) Multiple inheritance
c) Multilevel inheritance
d) Hierarchical inheritance

18. If a base class pointer is used to store the address of a derived class object and a non-virtual function is
called through this pointer, the base class function will be invoked, irrespective of the derived class's
definition.
a) True b) False
Answer: True
19. In C++, an abstract class can be instantiated if it has at least one virtual function defined in its base
class.
a) True b) False
Answer: False (An abstract class cannot be instantiated regardless of its functions' definitions.)
20. The visibility mode of inheritance impacts whether a derived class can override the private members of
its base class.
a) True b) False
Answer: False (Private members cannot be accessed or overridden by derived classes, regardless of
visibility mode.)

You might also like