Object Oriented Programming MCQs with Answers
Practice important Object Oriented Programming MCQs with answers and explanations.
Multiple Choice Questions
Q501: What is the result if a derived class object is used to call a function that exists in multiple base classes with the same signature, without explicitly specifying the base class?
- A: It will compile successfully
- B: It will throw a runtime error
- C: It will cause a compilation error
- D: It will override the function
View Answer
C
Q502: Fill in the blank: In a situation where a derived class inherits from a base class through multiple paths, using _______ inheritance avoids multiple copies of the base class object.
- A: Virtual
- B: Public
- C: Private
- D: Protected
View Answer
A
Q503: What is the main advantage of generic programming?
- A: Reusability
- B: Performance
- C: Complexity
- D: Memory usage
View Answer
A
Q504: What keyword is used to define a function template in C++?
- A: template
- B: function
- C: class
- D: struct
View Answer
A
Q505: In the function template `template< typename T > void printArray( T* array, int size )`, what does `T` represent?
- A: The array size
- B: The data type of the array elements
- C: The function name
- D: The template keyword
View Answer
B
Q506: Which of the following is a valid declaration of a function template in C++?
- A: template< class T > void funName( T x );
- B: template< void T > funName( T x );
- C: template< T class > void funName( T x );
- D: template< typename > void funName( x );
View Answer
A
Q507: What is the purpose of the `isEqual` function template?
- A: To compare two values of any type
- B: To print an array of elements
- C: To sort an array of elements
- D: To find the maximum value in an array
View Answer
A
Q508: In the function `template< typename T > bool isEqual( T x, T y )`, what happens when it is instantiated with `const char*`?
- A: It will compare the addresses of the strings
- B: It will compare the lengths of the strings
- C: It will use `strcmp` to compare the strings
- D: It will return false for any input
View Answer
C
Q509: What modification is needed for `isEqual` to correctly handle `const char*` types?
- A: Use `strcmp` for comparison
- B: Write a separate function for `const char*`
- C: Add `const char*` to the template parameters list
- D: Remove the template keyword
View Answer
C
Q510: In generic programming, what is the main drawback of function overloading?
- A: It requires writing multiple functions for different types
- B: It reduces code reusability
- C: It is harder to maintain
- D: It increases compile time
View Answer
A