© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu

Home Placements Interview Questions Java Interview Questions And Answers Java Interview Questions On Flow Control and Exception Handling ▼

Java Interview Questions On Flow Control and Exception Handling

14. What are checked exceptions?

Answer:
Checked exception are those which the Java compiler forces you to catch. e.g. IOException are checked Exceptions.

15. What are runtime exceptions?

Answer
Runtime exceptions are those exceptions that are thrown at runtime because of either wrong input data or because of wrong business logic etc. These are not checked by the compiler at compile time.

16. What is the difference between error and an exception?

Answer
An error is an irrecoverable condition occurring at runtime. Such as OutOfMemory error. These JVM errors and you can not repair them at runtime. While exceptions are conditions that occur because of bad input etc. e.g. FileNotFoundException will be thrown if the specified file does not exist. Or a NullPointerException will take place if you try using a null reference. In most of the cases it is possible to recover from an exception (probably by giving user a feedback for entering proper values etc.).

17. How to create custom exceptions?

Answer
Your class should extend class Exception, or some more specific type thereof.

18. Is it necessary that each try block must be followed by a catch block?

Answer
It is not necessary that each try block must be followed by a catch block. It should be followed by either a catch block OR a finally block. And whatever exceptions are likely to be thrown should be declared in the throws clause of the method.

19. If I write return at the end of the try block, will the finally block still execute?

Answer
Yes even if you write return as the last statement in the try block and no exception occurs, the finally block will execute. The finally block will execute and then the control return.

Previous Next
1 2 3 4 5 6 7 8 9
SLogix Student Projects
bottom