Answer Posted / sumesh babu r
The finally method will be executed after a try or catch
execution.
It is mainly used to free up resources.
The codes that must be executed, irrespective of whether the
exception is occurred or not, will be included in the
finally block.
See the following simple example to demonstrate the syntax
public class FinallyExample
{
public static void main(String args[])
{
try
{
// the code that may cause an exception
}
catch (Exception e)
{
// the code to be executed, when the exception
occurs
}
finally
{
// code to be executed irrespective of the
occurrence of exception
}
}
}
When using finally, the catch block is not mandatory.
ie, a try block must be followed by a catch or finally block.
| Is This Answer Correct ? | 3 Yes | 0 No |
Post New Answer View All Answers
Can an interface have a constructor?
Is a case study a method or methodology?
Why char array is preferred over string for storing password?
what is bmg file and how to create that files?what will it contailn?
How many bits is a double?
What is the difference between compiler and jvm?
How do you declare an array that will hold more than 64KB of data?
How can a gui component handle its own events?
Explain about assignment statement?
Can arraylist hold different types java?
What is the disadvantage of java?
Explain about automatic type conversion in java?
What is flag in java?
What is the old name of java?
What is type conversion in java?