UNIT 3-2mark
UNIT 3-2mark
18. What is the difference between checked and unchecked exceptions in Java?
Checked exceptions are exceptions that must be either caught and handled using try-catch blocks
or declared using the throws keyword in the method signature. Unchecked exceptions, also
known as runtime exceptions, do not need to be explicitly caught or declared.
19. What is the try-catch block used for in Java?
The try-catch block in Java is used for handling exceptions. Code that may throw exceptions is
enclosed within a try block, and the potential exceptions are caught and handled in one or more
catch blocks.
20. What is the purpose of the finally block in Java exception handling?
The finally block is used in Java exception handling to specify code that should be executed
regardless of whether an exception is thrown or not. It is typically used to release resources or
perform cleanup operations.
22. What is the purpose of the throws keyword in Java method signatures?
The throws keyword in Java method signatures is used to declare that a method might throw one
or more exceptions. It informs the caller of the method about the potential exceptions they need
to handle or propagate.