Object Oriented Programming MCQs with Answers
Practice important Object Oriented Programming MCQs with answers and explanations.
Multiple Choice Questions
Q561: What is the result of using the `template< class T, int I >` in C++?
- A: Partial specialization with a fixed integer value
- B: Complete specialization with a fixed integer value
- C: General template with two parameters
- D: Partial specialization with any integer value
View Answer
A
Q562: How is a complete specialization different from a partial specialization?
- A: Complete specialization fixes all template parameters, while partial specialization only fixes some.
- B: Complete specialization allows for multiple parameter types, while partial specialization does not.
- C: Partial specialization fixes all template parameters, while complete specialization only fixes some.
- D: Complete specialization is not allowed in C++, while partial specialization is.
View Answer
A
Q563: When creating an `Array` class with a non-type parameter for size, which declaration is correct?
- A: template< class T, int SIZE > class Array {};
- B: template< class T > class Array< SIZE > {};
- C: template< class T, int SIZE = 10 > class Array {};
- D: template< int SIZE > class Array {};
View Answer
C
Q564: What is the purpose of using `template< class T = int > class Vector { };`?
- A: To set a default type for the `Vector` class
- B: if no type is specified, it defaults to `int`
- C: To specify that `Vector` should only handle integers
- D: To create a vector of size 10 by default
View Answer
B
Q565: The `Vector< char* >` class is an example of ____.
- A: Partial specialization
- B: Complete specialization
- C: Function template specialization
- D: Non-type template parameters
View Answer
B
Q566: Which method is used to compare two pointers to objects of type `T`?
- A: `template< typename T > bool isEqual( T x, T y )`
- B: `template< typename T > bool isEqual( T* x, T* y )`
- C: `template< > bool isEqual< const char* >( const char* x, const char* y )`
- D: `template< class T > bool isEqual( T* x, T* y )`
View Answer
B
Q567: When using a default non-type parameter, what happens if no value is provided?
- A: The default value specified in the template definition is used.
- B: The compiler throws an error for missing parameter.
- C: The program uses the size provided at runtime.
- D: The template cannot be instantiated without specifying a non-type parameter.
View Answer
A
Q568: Which of the following shows correct default non-type parameter usage?
- A: template< class T, int SIZE = 10 > class Array {};
- B: template< class T > class Array< SIZE = 10 > {};
- C: template< int SIZE > class Array {};
- D: template< class T > class Array { int SIZE; };
View Answer
A
Q569: In which order does the compiler search for template specializations?
- A: Complete specialization, Partial specialization, General template
- B: Partial specialization, Complete specialization, General template
- C: General template, Complete specialization, Partial specialization
- D: Partial specialization, General template, Complete specialization
View Answer
A
Q570: What does the compiler use first when resolving a template specialization?
- A: Partial specialization
- B: Complete specialization
- C: General template
- D: Ordinary function
View Answer
B