Object-Oriented Programming Quiz & Answers

1. What are the three types of design patterns?
__________________

Answer: Creational, behavioral, structural. Source: Page XV of Design Patterns: Elements of Reusable Object-Oriented Software

2. As a recommended practice in OOP, which is preferred?

a. Object composition
b. Class inheritance
c. Programming to an implementation
d. none of the above

Answer: A. Source: Page 20 of Design Patterns: Elements of Reusable Object-Oriented Software

3. Polymorphism happens at which time?

a. Compile time
b. Run time
c. Both of the above
d. None of the above

Answer: C, but B could be an acceptable answer. For B, the source is page 361 of Design Patterns: Elements of Reusable Object-Oriented Software; apparently with C++, it is just at run-time.

The sources for C are these:
https://www.geeksforgeeks.org/difference-between-compile-time-and-run-time-polymorphism-in-java/
https://www.nerd.vision/post/polymorphism-encapsulation-data-abstraction-and-inheritance-in-object-oriented-programming

4. Inheritance happens at which time?

a. Compile time
b. Run time
c. Both of the above
d. None of the above

Answer: A. Source: Page 19 of Design Patterns: Elements of Reusable Object-Oriented Software and https://www.quora.com/What-is-meant-by-%E2%80%9Cinheritance-is-compile-time-and-composition-is-runtime%E2%80%9D

5. Composition in OOP happens at which time?

a. Compile time
b. Run time
c. Both of the above
d. None of the above

Answer: B Page 19 of Design Patterns: Elements of Reusable Object-Oriented Software. Source: https://www.quora.com/What-is-meant-by-%E2%80%9Cinheritance-is-compile-time-and-composition-is-runtime%E2%80%9D

6. With encapsulation, what is exposed?

a. Methods
b. Data
c. Both of the above
d. None of the above.

Answer: A. Source: https://www.nerd.vision/post/polymorphism-encapsulation-data-abstraction-and-inheritance-in-object-oriented-programming

7. When can objects (as in OOP) exist?

a. Objects can exist at compile time
b. Objects can exist at run time
c. Both of the above
d. None of the above

Answer: B. Page 361 of Design Patterns: Elements of Reusable Object-Oriented Software and
https://www.quora.com/When-an-object-is-created-is-it-during-compile-time-or-during-run-time.

8. What is another term for parent class?

a. Ancestor class
b. Base class
c. Superclass
d. All of the above
e. None of the above

Answer: D. Source: Page 361 of Design Patterns: Elements of Reusable Object-Oriented Software.

9. Which of the following programming languages allow for multiple inheritance of classes? Choose all that apply.

a. Python
b. Java
c. C++
d. C#
e. None of the above

Answer: A and C. Sources: Page 188 of Programming Interviews Exposed by Mongan, Kindler and Giguere (for why C is correct and B and D are incorrect). Page 118 of Learning Python for why A is correct.

Leave a comment

Your email address will not be published. Required fields are marked *