Object Oriented Programming MCQs with Answers
Practice important Object Oriented Programming MCQs with answers and explanations.
Multiple Choice Questions
Q551: Fill in the blank: The Vector<char*> specialization handles _______ by allocating and deallocating memory for character arrays.
- A: Shallow copy
- B: Deep copy
- C: Memory leak
- D: Static allocation
View Answer
B
Q552: What is the main issue with using Vector<char*> without specialization?
- A: It leads to shallow copying issues
- B: It results in compilation errors
- C: It causes memory overflow
- D: It produces incorrect data types
View Answer
A
Q553: In C++ templates, what does partial specialization involve?
- A: Changing the number of template parameters
- B: Changing the type of all template parameters
- C: Providing more specific types for some template parameters
- D: Using a single template parameter
View Answer
C
Q554: Which of the following is an example of complete specialization?
- A: template< class T > class Vector { };
- B: template< class T > class Vector< T* > { };
- C: template< class T, class U, class V > class A {};
- D: template<> class Vector< char* > { };
View Answer
D
Q555: What does the `insert` method in the `ComplexSet` class template do?
- A: It inserts a `Complex` instance into a `ComplexSet` object
- B: It removes a `Complex` instance from a `ComplexSet` object
- C: It updates a `Complex` instance in a `ComplexSet` object
- D: It searches for a `Complex` instance in a `ComplexSet` object
View Answer
A
Q556: Which type of parameters are not type parameters in templates?
- A: Template parameters
- B: Non-type parameters
- C: Type parameters
- D: Template arguments
View Answer
B
Q557: What will the following code result in? `template< typename T > bool isEqual( T x, T y ) { return ( x == y ); }`
- A: Comparing two objects of the same type
- B: Comparing two pointers of the same type
- C: Comparing two different types
- D: Comparing two const char* strings
View Answer
A
Q558: When using the `Complex` class template, what will happen if `Complex<float>` is assigned to `Complex<double>` without explicit specialization?
- A: It will work without any issues
- B: It will result in a compilation error
- C: It will automatically convert the types
- D: It will create a new `Complex
` instance without errors
View Answer
B
Q559: What does the member template `insert` in the `ComplexSet` class do?
- A: It adds a `Complex` object of any type to the set
- B: It removes a `Complex` object from the set
- C: It updates a `Complex` object in the set
- D: It retrieves a `Complex` object from the set
View Answer
A
Q560: The `Array` class template can use non-type parameters to specify ____.
- A: The type of elements
- B: The size of the array
- C: The constructor parameters
- D: The array's default value
View Answer
B