1.

Why do we use finally block?(a) To execute the block if exception occurred(b) To execute a code when exception is not occurred(c) To execute a code whenever required(d) To execute a code with each and every run of programThe question was asked at a job interview.My enquiry is from Exception Handling topic in portion Exception Handling & Static Class Members of Object Oriented Programming

Answer»

The correct choice is (d) To execute a code with each and every run of program

For EXPLANATION: Sometimes there is a need to execute a set of code every time the program RUNS. Even if the exception occurs and even if it doesn’t, there can be some code that must be executed at end of the program. That code is written in finally block. This block is ALWAYS executed REGARDLESS of exceptions OCCURRING.



Discussion

No Comment Found

Related InterviewSolutions