Java - Interview Questions and Answers on Exceptions

Q1.  Difference between Checked and Unchecked exceptions ?

Ans. Checked exceptions and the exceptions for which compiler throws an errors if they are not checked whereas unchecked exceptions and caught during run time only and hence can't be checked.

Q2.  How does a try statement determine which catch clause should be used to handle an exception?

Ans. When an exception is thrown within the body of a try statement, the catch clauses of the try statement are examined in the order in which they appear. The first catch clause that is capable of handling the exception is executed. The remaining catch clauses are ignored.

Q3.  Give an Example of checked and unchecked exception ?

Ans. ClassNotFoundException is checked exception whereas NoClassDefFoundError is a unchecked exception.

Q4.  Name few Java Exceptions ?

Ans. IndexOutofBound , NoClassDefFound , OutOfMemory , IllegalArgument.

Q5.  How can we make sure that a code segment gets executed even in case of uncatched exceptions ?

Ans. By putting it within finally.

Q6.  Explain java.lang.OutOfMemoryError ?

Ans. This Error is thrown when the Java Virtual Machine cannot allocate an object because it is out of memory, and no more memory could be made available by the garbage collector.

Q7.  Is it necessary that each try block to be followed by catch block ? 

Ans. It should be followed by either catch or finally block.

Q8.  Can finally block be used without catch ?

Ans. Yes but should follow "try" block then.

Q9.   What is exception propogation ?

Ans. Passing the exception object to the calling method.

Q10. What is the package name for IOexception class?

Q11. Which is the Parent Class of IOexception?


Q12. Which interfaces are implemented by FileNotFoundException?


Q13. Which interfaces are implemented by IllegalArgumentException?


Q14. Which is the Parent Class of FileNotFoundException?


Q15. What is the package name for Exception class?

Q16. Which is the Parent Class of Exception class?


Q17. Which interfaces are implemented by Exception?


Q18. Which interfaces are implemented by IOexception?


Q19. What is the package name for FilenotFoundException class?

Q20. What is the package name for IllegalArgumentException class?

Q21. Which is the Parent Class of IllegalArgumentException?


Subscribe to Java News and Posts. Get latest updates and posts on Java from
Enter your email address:
Delivered by FeedBurner
comments powered by Disqus