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 we write class inside a class in java?
Is there any case when finally will not be executed?
What is difference between length and length() method in java ?
How objects are stored in java?
Why is string class considered immutable?
What is the difference between pass by reference and pass by pointer?
What is array initialization in java?
How are multiple inheritances done in Java?
What is a numeric format?
What are the advantages of encapsulation in java?
Can I overload to string method
What is identifier give example?
What’s the difference between applets and standalone program?
Can we extend singleton class in java?
What is the final variable?