A developer is writing a Java application that processes a large number of transactions. The application must ensure that each transaction is committed only if all steps complete successfully, otherwise the entire transaction should be rolled back. Which Java concept should the developer use to implement this requirement?
Trap 1: Inheritance
Inheritance is for code reuse, not transaction management.
Trap 2: Multithreading
Multithreading handles concurrent execution, not transactional integrity.
Trap 3: Encapsulation
Encapsulation hides data, not manage transactions.
- A
Exception handling
Exception handling can catch failures and trigger rollback.
- B
Inheritance
Why wrong: Inheritance is for code reuse, not transaction management.
- C
Multithreading
Why wrong: Multithreading handles concurrent execution, not transactional integrity.
- D
Encapsulation
Why wrong: Encapsulation hides data, not manage transactions.