Java Exception Handling Question and Answers

9. What is the difference between checked and unchecked exception?
 
  • Checked Exception: Environmental error that cannot necessarily be detected by testing; e.g. disk full, broken socket, database unavailable etc.
  • Unchecked Exception: Virtual machine error: class not found, out of memory, no such method, illegal access to private field, etc.
 
Your Name Your Email-ID
Your Answer
10. Can an exception be rethrown?
  Yes, an exception can be rethrown.
 
Your Name Your Email-ID
Your Answer
11. What is null pointer exception?
  A null pointer exception is thrown when calling the instance method of a null object, accessing or modifying the field of a null object etc.
 
Your Name Your Email-ID
Your Answer
12. What is the difference between final, finally and finalize()?
 
  • final: It is a modifier which can be applied to a class, method or variable.
    It is not possible to inherit the final class, override the final method and change the final variable.
  • finally: It is an exception handling code section.
    It gets executed whether an exception is raised or not by the try block code segment.
  • finalize() It is a method of Object class.
    It is executed by the JVM just before garbage collecting object to give a final chance for resource releasing activity.
    Out of the three, only finally is related to java exception handling.
 
Your Name Your Email-ID
Your Answer
1234 Page 3 of 4