DR.
BR AMBEDKAR NATIONAL INSTITUTE OF TECHNOLOGY, JALANDHAR
QUIZ III
Name: Roll No: Department: INFORMATION TECHNOLOGY
Course Title: Object Oriented Programming Concepts Course Code: ITDC0201 Marks Obtained:
Duration: 10 Minutes Total Marks: 5 Marks Date: 26 November, 2024
Each question carries 0.25 marks.
1. Which visibility mode allows derived classes to access protected members of the base class?
a) Public inheritance b) Private inheritance
c) Protected inheritance d) Both a and c
2. What happens if a derived class does not override a pure virtual function in the base class?
a) The derived class becomes abstract. b) The derived class causes a compilation error.
c) The base class implementation is used. d) The derived class becomes inaccessible.
3. In C++, if a class has at least one _______________ function, it becomes an abstract class.
4. If class A privately inherits class B, which members of B are accessible in A?
a) Public members only. b) Protected members only.
c) Both public and protected members. d) None of the above.
5. Can a class inherit from multiple classes with identical member function names?
a) No, compilation error occurs.
b) Yes, but requires disambiguation in the derived class.
c) Yes, without any restrictions.
d) No, only virtual inheritance is allowed.
6. What is the correct way to declare a virtual function in a base class?
a) virtual void func(); b) void virtual func();
c) void func() virtual; d) virtual func();
7. If a base class pointer points to a derived class object and a virtual function is called using the pointer,
_______________ binding is used.
8. Consider the following code snippet:
class A {
protected:
int x;
};
class B : private A {
public:
void setX(int val) { x = val; }
};
In the derived class B, the member x is
a) Public b) Private
c) Protected d) Inaccessible
9. If __________________ inheritance is done continuously, it is similar to tree structure.
10. What is the minimum number of classes to be there in a program implementing hybrid inheritance?
a) 2 b) 3
c) 4 d) No limit
11. Overloading operators are possible only by using hybrid inheritance.
a) True b) False
12. Consider the following:
class A {
public:
int a; };
class B : private A {
public:
void setA(int x) { a = x; } };
class C : public B {
public:
void show() { cout << a; } };
C fail to access a because ___________________________________________.
13. If hybrid inheritance is used, it mostly shows _______________ feature of OOP.
a) Flexibility b) Reusability
c) Efficiency d) Code readability
14. Do members of base class gets divided among all of its child classes?
a) Yes, equally b) Yes, depending on type of inheritance
c) No, it is doesn’t get divided d) No, it may or may not get divided
15. If one class have derived the base class privately then another class can’t derive the base class publically.
a) True b) False
16. Consider the following scenario:
class A { public: void func(int x) { cout << x; } };
class B : public A { public: void func(double y) { cout << y; } };
B obj;
obj.func(5);
What will be the output?
a) 5 b) Error due to ambiguity
c) Implicit conversion: 5.0 d) Compile-time error
17. To call the base class version of a function from a derived class that has overridden it, the syntax used is
______________________________.
18. A class Shape has a pure virtual function draw(). Which of the following is correct about the derived class
Circle that inherits Shape?
a) Circle must implement draw() to be instantiated.
b) Circle can choose not to implement draw().
c) Circle cannot add new pure virtual functions.
d) Shape cannot have a destructor.
19. In polymorphism, calling a base class function from a derived class object is resolved at _______________
time if the function is not virtual.
20. Which scenario will cause a compilation error in multiple inheritance?
a) Both base classes declare a virtual function with the same name but different parameters.
b) Both base classes declare a pure virtual function with the same name.
c) Both base classes have a constructor with the same signature.
d) Both base classes declare a non-virtual function with the same name.