Object Oriented Programming MCQs with Answers
Practice important Object Oriented Programming MCQs with answers and explanations.
Chapter: 39
Q601:
How many separate copies of static data members are created for different data types in a template class?
A. One
B. Two
C. Three
D. Four
Correct Answer:
B
Chapter: 39
Q602:
Which rule states that when a function template or class template is a friend of a template class, it becomes a friend for each instantiation of that template class for a specific type?
A. Rule 1
B. Rule 2
C. Rule 3
D. Rule 4
Correct Answer:
B
Chapter: 39
Q603:
Fill in the blank: When an ordinary function or class is declared as a friend of a template class, it becomes a friend of each _______ of that template class.
A. instantiation
B. method
C. static member
D. object
Correct Answer:
A
Chapter: 39
Q604:
In the provided find function template, what operations are necessary for a container to be compatible with this algorithm?
A. Increment operator and dereferencing operator only
B. Increment operator, dereferencing operator, and inequality operator
C. Only dereferencing operator
D. Only inequality operator
Correct Answer:
B
Chapter: 39
Q605:
Fill in the blank: In the find function template, the P parameter represents the type of _______ used for traversal in the algorithm.
A. iterator
B. container
C. function
D. class
Correct Answer:
A
Chapter: 39
Q606:
What will happen if you try to use the find function with a container that does not support the increment operator?
A. Compilation will fail
B. The function will return incorrect results
C. The function will still work as expected
D. The container will be ignored
Correct Answer:
A
Chapter: 39
Q607:
In the Vector class example, what data type is the index data member used to track?
A. Size
B. Traversal position
C. Value
D. Capacity
Correct Answer:
B
Chapter: 39
Q608:
What does Rule 4 state about friend templates in relation to specializations?
A. All specializations of the friend template become friends
B. Only explicit specializations become friends
C. Only partial specializations become friends
D. Specializations are not considered friends
Correct Answer:
A
Chapter: 39
Q609:
Fill in the blank: If a template class A is declared as a friend of a template class B, then the friend declaration applies to _______ specializations of A.
A. explicit, implicit, and partial
B. only explicit
C. only partial
D. only implicit
Correct Answer:
A
Chapter: 40
Q610:
In the context of cursors, what does the `beyond()` method return?
A. The first element of the container
B. The last element of the container
C. The pointer just past the last element
D. The pointer to the middle element
Correct Answer:
C
Chapter: 40
Q611:
What is a primary advantage of using cursors over traditional pointers in the Vector class?
A. No need for multiple Vector objects
B. Supports non-contiguous containers
C. Reduces memory consumption
D. Allows for backward traversal
Correct Answer:
A
Chapter: 40
Q612:
Which method in the Vector class returns a pointer to the first element?
A. `beyond()`
B. `next()`
C. `first()`
D. `last()`
Correct Answer:
C
Chapter: 40
Q613:
What problem arises when using cursors with non-contiguous containers?
A. Cursors do not support multiple traversals
B. Cursors cannot traverse backward
C. Cursors fail to increment correctly
D. Cursors provide incorrect element values
Correct Answer:
C
Chapter: 40
Q614:
In the Iterator class, what operation does the `operator++()` perform?
A. Decrements the iterator
B. Increments the iterator
C. Returns the current element
D. Checks if two iterators are equal
Correct Answer:
B
Chapter: 40
Q615:
What is the main benefit of using iterators over cursors?
A. They provide direct access to internal data
B. They support multiple traversal strategies
C. They are easier to implement
D. They are faster for all operations
Correct Answer:
B
Chapter: 40
Q616:
What does the `find` function using cursors require as parameters?
A. Container size, element to find, and a pointer to the container
B. Pointer to start, pointer to beyond, and the element to find
C. Container name, start index, and end index
D. Pointer to start, pointer to end, and a boolean flag
Correct Answer:
B
Chapter: 40
Q617:
Which operation is NOT supported by cursors?
A. Pointer arithmetic
B. Incrementing the pointer
C. Direct access to internal container data
D. Traversing non-contiguous containers
Correct Answer:
D
Chapter: 40
Q618:
In the provided Vector class code, what is the purpose of the `next()` method?
A. It returns the pointer to the next element in the container
B. It increments the container size
C. It returns the last element in the container
D. It resets the pointer to the first element
Correct Answer:
A
Chapter: 40
Q619:
The `find` function is designed to work with which of the following?
A. Only contiguous containers
B. Any container with specific operations
C. Only vector containers
D. Containers with pointers only
Correct Answer:
B
Chapter: 40
Q620:
What is the role of the `operator*()` in the Iterator class?
A. It increments the iterator
B. It returns the element pointed to by the iterator
C. It checks if two iterators are equal
D. It assigns a new value to the iterator
Correct Answer:
B