Why we need Finally with try?
pls expain with ur example..

Answer Posted / neha

finally block gets executed in both scenarios I.e exception occurs or doesn't occur..it is used to write the code which we want to execute in both successful or failed scenarios..generally code for cleaning up resources added in finally block.e.g closing file,closing socket connection.

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is meant by inheritance and what are its advantages?

572


What is prefix of a string?

564


Explain about arraylist?

571


Are primitives objects?

562


Tell me about different OOPS concepts.

585






How do you add an element to a hashset in java?

486


How many types of operators are there?

516


Is 0 true or false in java?

515


How to make a class or a bean serializable?

537


Why to use nested classes in java? (Or) what is the purpose of nested class in java?

519


What is the difference between serializable and externalizable interface?

563


What is currentthread()?

568


Is singleton set an interval?

526


What is the difference between throw and throws keywords?

569


what are the methods in object?

631