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
Are arrays passed by reference in java?
Differentiate between run time error and syntax error.
What is meant by memory leak?
Can we assign null to double in java?
What does it mean to be immutable?
What is difference between path and classpath variables?
Write a program to calculate factorial in java?
What is mutable object and immutable object?
Why is it called a string?
How do you square a number in java?
What does provide mean construction?
What is the difference between an interface and an abstract class?
What is the use of beaninfo?
What is hotjava?
Why do we need hashmap in java?