Search your topic in Java2share
Home > FAQs
eXTReMe Tracker


Exception Handling FAQs


Untitled Document

Q17. If return statement present inside try is finally block will be executed?
Ans. Yes, if return statement present inside try, then also finally block will be executed. finally block will dominate return statement also.

Q18. What is the difference between final, finally and finalize()?
Ans. final:- final is a modifier applicable for variables, methods and classes. final variable means constant and reassignment is not possible. final method means implementation is final in the child classes we can’t override. final class means it won’t participate in inheritance and child class creation is not possible.
finally:- It is a block associated with try catch to maintain cleanup code. Finally block will be executed always irrespective of whether exception is raised or not raised or whether the exception is handle or not handle.
finalize():- It is a method, Garbage collector always calls this method just before destroying any object to perform cleanup activities.

Q19. Is it possible to write any statement between try-catch and finally?
Ans. No, it is not possible to write any statement between try catch and finally. If we will try to write any statement between them then we will get compile time error.

Q20. Is it possible to take two finally blocks for the same try?
Ans. No, it is not possible to take two finally blocks for the same try. If we try to take then we will get compile time error.