Object Oriented Programming MCQs with Answers
Practice important Object Oriented Programming MCQs with answers and explanations.
Chapter: 21
Q321:
In the statement cout << y++;, what value is printed?
A. The incremented value of y
B. The original value of y
C. An error occurs
D. Garbage value
Correct Answer:
B
Chapter: 21
Q322:
What is the output of the following code? int y = 2; ++y; cout << y;
A. 2
B. 3
C. 4
D. 1
Correct Answer:
B
Chapter: 21
Q323:
In the modified String class, how is the post-increment operator (++) implemented?
A. Using a non-member function
B. Using a friend function
C. Using a member function
D. Using a static function
Correct Answer:
C
Chapter: 21
Q324:
The post-increment operator (++) in a class returns:
A. The current object
B. A temporary object
C. The original object
D. A null object
Correct Answer:
B
Chapter: 21
Q325:
Which of the following is required to convert a user-defined type to another type?
A. A constructor with a single parameter
B. A destructor
C. An operator function
D. A copy constructor
Correct Answer:
A
Chapter: 21
Q326:
What keyword is used in C++ to restrict automatic type conversion in constructors?
A. implicit
B. explicit
C. auto
D. final
Correct Answer:
B
Chapter: 21
Q327:
The function operator int() in the String class converts a String object to which type?
A. char *
B. int
C. double
D. float
Correct Answer:
B
Chapter: 21
Q328:
Which operator is overloaded to convert a String object to a char * in the String class?
A. operator int()
B. operator float()
C. operator char *()
D. operator void()
Correct Answer:
C
Chapter: 21
Q329:
When overloading a unary operator as a member function, how many parameters does it take?
A. None
B. One
C. Two
D. Three
Correct Answer:
A
Chapter: 21
Q330:
Which of the following is a drawback of type conversion operators in C++?
A. They are too complex to implement
B. They cause unexpected conversions
C. They are inefficient
D. They cannot be overloaded
Correct Answer:
B
Chapter: 21
Q331:
What is the result of using the explicit keyword in a constructor?
A. The constructor becomes private
B. The constructor cannot be overloaded
C. Automatic type conversion is disabled
D. The constructor must be static
Correct Answer:
C
Chapter: 21
Q332:
What does the following code do? String s(‘A’); cout << s.GetStringPtr();
A. Outputs "A"
B. Outputs "65"
C. Outputs "A65"
D. Causes a runtime error
Correct Answer:
B
Chapter: 21
Q333:
Which of the following will cause an error due to the use of the explicit keyword in the constructor?
A. String s = 65;
B. String s; s = String(101);
C. String s; s = ‘A’;
D. String s; s = (String)101;
Correct Answer:
C
Chapter: 21
Q334:
How does the compiler differentiate between pre-increment and post-increment in operator overloading?
A. By the number of parameters
B. By the return type
C. By the dummy parameter
D. By the function name
Correct Answer:
C
Chapter: 21
Q335:
In the following code, what is returned by the operator++(int) function? Complex h1; h1++;
A. The original value of h1
B. The incremented value of h1
C. A temporary object
D. A null object
Correct Answer:
C
Chapter: 21
Q336:
Which type of function is typically used for user-defined type conversion from the current type to another type?
A. Constructor
B. Destructor
C. Copy constructor
D. Operator function
Correct Answer:
D
Chapter: 21
Q337:
Which keyword is used to prevent implicit type conversions in C++?
A. const
B. virtual
C. explicit
D. static
Correct Answer:
C
Chapter: 21
Q338:
The following code causes a type conversion. What is being converted? String s = 345;
A. int to String
B. String to char *
C. String to int
D. char * to String
Correct Answer:
A
Chapter: 21
Q339:
What is the output of the following code? String s("1234"); cout << (char *)s;
A. "1234"
B. 1234
C. Junk value
Correct Answer:
A
Chapter: 21
Q340:
What will be the result of using explicit keyword with a constructor when a string is initialized as String s = ‘A’;?
A. Causes a compile-time error
B. Causes a runtime error
C. Initializes with "A"
D. Initializes with "65"
Correct Answer:
A