Professional Documents
Culture Documents
OOP2 Prelims
OOP2 Prelims
1. A Vehicle class has subclasses like Car. 11. A bank account class contains balance
Bicycle. and Motorcycle. These subclasses information and external code interacts
will still have the common features of the through well-defined methods.
Vehicle (e.g., wheels, engine) while the - E
subclass adds their specific details. 12. Allows a new class to inherit properties and
- I behaviors from an existing class.
2. Restricts direct access to internal details, - I
promoting data protection. 13. Promotes the “is-a” relationship of objects.
- E - I
3. Allows flexibility by providing a single interface 14. Ensures that data remains private and can
for multiple related classes. only be accessed through controlled
- A interfaces.
4. Facilitates the reuse of code and extensibility. - E
- I 15. Access modifiers (public, private, package-
5. Promotes creating generic functions. private, protected) play a role in this principle.
- A - E
6. Also known to perform late-binding. 16. Allows us to focus on what an object does
- P rather than how it does it.
7. Hiding the implementation details of an object - A
or system and exposing only essential features 17. Focuses on creating a hierarchy of classes.
that the user only needs to know. - I
- A 18. A Shape class has subclasses like Circle,
8. Provides a high-level view of the system. Rectangle, and Triangle and despite having
- A different implementations, the Shape class
9. Allows dynamic method dispatch and runtime can be used to call their common methods
flexibility. like calculatePerimeter().
- P - P
10. The computer only has keys and a mouse for 19. Bundles data and methods into a single unit.
you to interact with it, wherein you don't have - E
to worry about how it works internally. 20. Enables objects of different types to be
- A treated uniformly.
- P
Identification.
True or False
Essay.
2. During the previous activity, why do you think the ArrayFullException was a checked exception
and the InvalidPositionException an unchecked exception.
The decision to make ArrayFullException a checked exception might be because a full array
is a foreseeable and recoverable condition that the calling code should handle explicitly. On the
other hand, InvalidPositionException may be an unchecked exception because it represents an
unexpected and potentially unrecoverable error, and forcing every method to declare it might be
impractical or burdensome.
3. A method, when performing a task that may throw an exception, becomes an exception
thrower. An exception thrower has two types: a propagator and a catcher. An exception catcher
is conceptually good since calls to the method will surely not result in an exception thrown.
However when should we make one a propagator and not a catcher?
The purpose of a finally block is to contain code that must be executed regardless of
whether an exception is thrown or not, providing a reliable way to perform cleanup operations,
such as releasing resources. Unlike placing code after the entire try-catch block, a finally block
ensures execution even if an exception occurs, making it suitable for tasks that must be
performed in both normal and exceptional cases, enhancing code reliability and
maintainability.
5. What are the two techniques of creating threads? Describe how one is better than the other.
The two techniques of creating threads in Java are extending the Thread class and
implementing the Runnable interface. Implementing the Runnable interface is often considered
better because it allows better separation of concerns, as a class can extend another class
while implementing multiple interfaces, promoting a more flexible and modular design
compared to the single inheritance constraint of extending the Thread class.