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




Answers were Sorted based on User's Feedback



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

Answer / kedar lasane from tuljapur

Because Some Instructions that must be executed in our java
program though there is exception in try block caught by
catch.Once the Exception occurs it catched by catch
statement and control never goes to try block again.So to
Execute some statements after subsequent with try block then
finally {} block is used.Hopefully You find your solution.If
any questions regaurding to java just mail me.
--------------
thnx
my blog: http://www.tuljabhavani.in

Is This Answer Correct ?    33 Yes 4 No

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

Answer / uppaluri

Finally Block always executes when the try block exists. Finally is used for more than exception handling : It allows the Programmer to avoid having cleanup code accidentally bypassed by a return, continue, or break. Putting cleanup code in a finally block is always a good practice. Hopefully you find your Solution.If you have any questions regarding Java mail me

Is This Answer Correct ?    15 Yes 6 No

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

Answer / 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



More Core Java Interview Questions

What is the preferred size of a component?

3 Answers   ITSA,


Explain role of constructor in a java application?

5 Answers  


Can a class be subclass of itself?

4 Answers  


Why non nested classes in java are not having marked as protected access specifier

2 Answers   Google,


what are upcasting and downcasting?

5 Answers  






what is the role of xml in core java?? and how we can use it?? can somebody give a sample program with explanation and from where i can read more about xml?????

0 Answers   HCL, SAP Labs, Vital Soft,


can we overload main method?

8 Answers   TCS,


what is the messsage u r going to get from an objectoriented programing?

0 Answers   MGL,


How to sort a vector elements that contains the user define class object? (Note: If Suppose consider, A Student class contain two data members. They are String studentName and int rollNo. I am creating Four objects for this class, each object contains students details like name and roll no. Now i am storing that objects in vector and if i retiving the elements from the vector means then it should be display in sorting order)

3 Answers   ProdEx Technologies,


what is inner class?

6 Answers   HCL,


what is the logic inside any default constuctor?

2 Answers  


what is translator and it types

1 Answers  






Categories