Object Oriented Programming MCQs with Answers
Practice important Object Oriented Programming MCQs with answers and explanations.
Chapter: 7
Q121:
In C++, which keyword is used to define a class?
A. class
B. structure
C. object
D. type
Correct Answer:
A
Chapter: 8
Q122:
Member functions operate on the data _______ in a class.
A. class
B. package
C. object
D. parameter
Correct Answer:
A
Chapter: 8
Q123:
In C++, you can define member functions _______ the class definition or inside it.
A. both inside and outside
B. only inside
C. only outside
D. none of the above
Correct Answer:
A
Chapter: 8
Q124:
Which keyword is used to request the compiler to make a function inline?
A. inline
B. implicit
C. explicit
D. static
Correct Answer:
A
Chapter: 8
Q125:
The compiler-generated default constructor is known as _______.
A. explicit
B. constructor
C. implicit
D. none of the above
Correct Answer:
C
Chapter: 8
Q126:
If a class has a parameterless constructor, it is called a _______ constructor.
A. default
B. explicit
C. implicit
D. parameterized
Correct Answer:
A
Chapter: 8
Q127:
A copy constructor is used for _______ an object.
A. creating a new object with the state of an existing one
B. modifying an existing object
C. overloading a function
D. none of the above
Correct Answer:
A
Chapter: 8
Q128:
What is the purpose of the 'inline' keyword in C++?
A. To make functions faster by avoiding function call overhead
B. To increase function visibility
C. To decrease function size
D. To provide default values for function parameters
Correct Answer:
A
Chapter: 8
Q129:
In which case does the default copy constructor not work properly?
A. When the class involves dynamic memory allocation
B. When the class has no constructors
C. When the class is empty
D. When the class uses only static members
Correct Answer:
A
Chapter: 8
Q130:
When creating a `Student` object with the constructor `Student(int aRollNo)`, which data member is initialized?
A. rollNo
B. name
C. GPA
D. none of the above
Correct Answer:
A
Chapter: 8
Q131:
What is the result of using the statement `Student studentB = studentA;` if a copy constructor is not explicitly defined?
A. The default copy constructor is used
B. The compiler throws an error
C. A deep copy is performed
D. A shallow copy is performed
Correct Answer:
A
Chapter: 8
Q132:
Fill in the blank: Inline functions are typically _______ in size and called frequently.
A. small
B. large
C. medium
D. none of the above
Correct Answer:
A
Chapter: 8
Q133:
What does the `setRollNo` function in the `Student` class do?
A. Sets the roll number of the student
B. Displays the student's name
C. Calculates the student's GPA
D. None of the above
Correct Answer:
A
Chapter: 9
Q134:
What is a copy constructor used for in C++?
A. Initializing an object with the state of a pre-existing object
B. Performing arithmetic operations
C. Creating new objects from scratch
D. Deleting objects
Correct Answer:
A
Chapter: 9
Q135:
Which of the following is a correct syntax for a copy constructor?
A. Student::Student(Student &obj) { ... }
B. Student::Student(const Student &obj) { ... }
C. Student::Student(Student obj) { ... }
D. Student::Student(const Student obj) { ... }
Correct Answer:
B
Chapter: 9
Q136:
What does a shallow copy involve?
A. Creating a new object with a new memory allocation for dynamic members
B. Copying data members bit by bit to a new object
C. Reinitializing an existing object
D. Deleting an object
Correct Answer:
B
Chapter: 9
Q137:
In the context of copy constructors, what is the problem with shallow copying when dealing with dynamic memory?
A. Dangling pointer issue
B. Memory leak issue
C. Buffer overflow issue
D. None of the above
Correct Answer:
A
Chapter: 9
Q138:
What is the purpose of deep copying?
A. To avoid issues with dangling pointers
B. To create a new object with the same memory reference
C. To speed up object creation
D. To reduce memory usage
Correct Answer:
A
Chapter: 9
Q139:
Fill in the blank: Shallow copy performs a _____ copy of data members.
A. bitwise
B. deep
C. dynamic
D. shallow
Correct Answer:
D
Chapter: 9
Q140:
Fill in the blank: In a deep copy, a new dynamic memory allocation is made for the _____ members of a class.
A. static
B. public
C. private
D. dynamic
Correct Answer:
D