OODP question bank for unit 1 and unit 2
OODP question bank for unit 1 and unit 2
Multiple‐Choice Questions
1. Which of the following is NOT considered a core principle of Object-Oriented
Programming (OOP)?
A) Encapsulation
B) Inheritance
C) Abstraction
D) Compilation
2. Which of the following is NOT a primitive data type in C++?
A) int
B) bool
C) string
D) float
3. Find the output of the following C++ code snippet:
#include <iostream>
using namespace std;
int main() {
int a = 5, b = 10;
cout << a + b;
return 0;
}
A) 5
B) 10
C) 15
D) 20
4. In UML, a dashed arrow typically represents:
A) Dependency
B) Inheritance
C) Association
D) Aggregation
5. In C++, which keyword is used to inherit publicly from a base class?
A) inherits
B) public
C) extends
D) private
6. When is a constructor called in C++?
A) When an object is destroyed
B) When an object is created
C) When a class is declared
D) When a function is defined
7. How many constructors can a C++ class have?
A) Only one
B) Two
C) Multiple
D) Zero
8. Which of the following statements about operator overloading in C++ is TRUE?
A) Only member functions can be overloaded
B) Only non-member functions can be overloaded
C) Both member and non-member functions can be overloaded
D) Operators cannot be overloaded
9. In UML class diagrams, what does a solid diamond represent?
A) Inheritance
B) Aggregation
C) Composition
D) Association
10. Which access specifier allows derived classes to access base class members in C++?
A) private
B) protected
C) public
D) friend
11. Which of the following declarations defines a constant pointer in C++?
A) int *const ptr
B) const int *ptr
C) int const *ptr
D) const int *const ptr
12. Which keyword is used to define a namespace in C++?
A) package
B) module
C) namespace
D) system
13. Which of the following is NOT a valid access specifier in C++?
A) public
B) protected
C) private
D) secure
14. Which UML diagram is primarily used for representing the flow of control in a system?
A) Use Case Diagram
B) Activity Diagram
C) Class Diagram
D) Component Diagram
15. What is the primary purpose of the “friend” keyword in C++?
A) To enable inheritance
B) To allow external functions to access private members
C) To overload operators
D) To declare virtual functions
16. Which of the following best describes polymorphism in OOP?
A) The ability to encapsulate data
B) The ability to inherit methods
C) The ability to process objects differently based on their types
D) The ability to abstract classes
17. Which operator is used to access members of a structure in C++?
A) .
B) ->
C) ::
D) Both A and B
18. Which of the following correctly describes function overloading in C++?
A) Functions with the same name but different return types
B) Functions with different names but the same functionality
C) Functions with the same name and different parameter lists
D) Functions with the same name and identical parameter lists.
19. Which of the following is a valid way to write a single-line comment in C++?
A) // This is a comment
B) /*
C) %% This is a comment %%
D) ** This is a comment **
20. Which file extension is typically used for a C++ source file?
A) .c
B) .cpp
C) .cs
D) .java
21. Which library must be included to use input/output objects like cin and cout?
A) <stdio.h>
B) <stdlib.h>
C) <iostream>
D) <string>
22. What is the output of the following C++ code snippet?
#include <iostream>
using namespace std;
int main() { cout << "Hello, World!"; return 0; }
A) Hello, World!
B) "Hello, World!"
C) cout << "Hello, World!";
D) No output
23. Which of the following correctly declares an integer variable named num in C++?
A) int num;
B) integer num;
C) num int;
D) var num;
24. Which operator is used to access the value at the memory address stored in a pointer?
A) &
B) *
C) ->
D) %
25. How do you correctly create a pointer to an integer variable named var?
A) int* ptr = var;
B) int ptr = &var;
C) int* ptr = &var;
D) pointer int ptr = var;
PART B QUESTIONS:
4. Create a C++ program that utilizes function overloading to perform arithmetic operations.
Implement overloaded functions to handle addition, subtraction, and multiplication for
both integers and floating-point numbers. The functions should differ by the number and
types of parameters.