Skip to main content

Object Oriented Programming MCQs with Answers

Practice important Object Oriented Programming MCQs with answers and explanations.

Chapter: 30
Q481:
What is the purpose of using polymorphism in a payroll application?
A. To calculate salaries based on employee type
B. To handle user input
C. To generate reports
D. To manage database connections
Correct Answer: A
Chapter: 30
Q482:
Which method in the Employee class is used to calculate salary?
A. getName
B. calcSalary
C. getTax
D. applyBonus
Correct Answer: B
Chapter: 30
Q483:
What is the base class in the payroll application example?
A. SalariedEmp
B. Employee
C. HourlyEmp
D. CommEmp
Correct Answer: B
Chapter: 30
Q484:
How does the SalariedEmp class calculate salary?
A. By multiplying salary with tax rate
B. By adding salary and tax
C. By subtracting tax from salary
D. By multiplying hourly rate with hours worked
Correct Answer: C
Chapter: 30
Q485:
What type of employee object is used to represent an employee paid by the hour?
A. SalariedEmp
B. HourlyEmp
C. CommEmp
D. TemporaryEmp
Correct Answer: B
Chapter: 30
Q486:
Which class in the example represents an employee with a commission-based salary?
A. SalariedEmp
B. HourlyEmp
C. CommEmp
D. ManagerEmp
Correct Answer: C
Chapter: 30
Q487:
In the generatePayroll function, what type of array is used to store employee objects?
A. Array of objects
B. Array of pointers to objects
C. Array of integers
D. Array of strings
Correct Answer: B
Chapter: 30
Q488:
What is the correct way to achieve polymorphism with arrays in C++?
A. Use arrays of objects
B. Use arrays of pointers to objects
C. Use arrays of integers
D. Use arrays of strings
Correct Answer: B
Chapter: 30
Q489:
What is a common mistake when trying to use polymorphism with arrays?
A. Using arrays of pointers
B. Using arrays of objects
C. Incorrectly calculating memory addresses
D. Not initializing arrays
Correct Answer: C
Chapter: 30
Q490:
Which of the following statements is true regarding the use of arrays of objects for polymorphism?
A. They cause runtime errors due to incorrect address calculation
B. They work correctly and efficiently
C. They are easy to implement without issues
D. They are used for managing pointers to objects
Correct Answer: A
Chapter: 30
Q491:
How does polymorphism work in the context of the Shape class and its derived classes?
A. By using base class pointers to derived class objects
B. By using arrays of base class objects
C. By directly calling methods on derived class objects
D. By using only base class methods
Correct Answer: A
Chapter: 30
Q492:
What is the result of using arrays of objects in the drawShapes function?
A. The program compiles but may terminate abnormally
B. Correctly draws all shapes without issues
C. Displays only the base class output
D. Produces a compile-time error
Correct Answer: A
Chapter: 30
Q493:
In the context of the payroll application, what does the calcSalary method in CommEmp class compute?
A. Gross pay after tax
B. Total sales
C. Commission rate
D. Salary before tax
Correct Answer: A
Chapter: 30
Q494:
What should be used instead of an array of objects to achieve correct polymorphic behavior?
A. Array of pointers to objects
B. Array of integers
C. Array of characters
D. Array of floats
Correct Answer: A
Chapter: 31
Q495:
In C++, a class can inherit from how many classes using multiple inheritance?
A. Only one
B. Two
C. Three
D. More than one
Correct Answer: B
Chapter: 31
Q496:
Which inheritance mode allows derived classes to access public and protected members of the base class?
A. Private Inheritance
B. Protected Inheritance
C. Public Inheritance
D. Virtual Inheritance
Correct Answer: C
Chapter: 31
Q497:
What happens if a derived class inherits from two base classes that have a function with the same signature?
A. The derived class will have one copy of the function
B. The derived class will have two copies of the function
C. The function will be overridden in the derived class
D. An error will occur
Correct Answer: B
Chapter: 31
Q498:
Fill in the blank: In multiple inheritance, when a derived class inherits from two base classes with the same method, the compiler might face _______ due to the presence of two identical methods.
A. Ambiguity
B. Clarity
C. Precision
D. Simplicity
Correct Answer: A
Chapter: 31
Q499:
Which type of inheritance ensures that only one copy of a base class object is generated in a derived class?
A. Virtual Inheritance
B. Public Inheritance
C. Private Inheritance
D. Protected Inheritance
Correct Answer: A
Chapter: 31
Q500:
Fill in the blank: The C++ feature that allows a class to inherit from more than one class is known as _______.
A. Multiple Inheritance
B. Single Inheritance
C. Hybrid Inheritance
D. Virtual Inheritance
Correct Answer: A

Test Your Knowledge

Take a timed quiz on Object Oriented Programming

🚀 Start Quiz Now