What is the difference between final, finally, finalize() in java?

This is one of the important question, if you attend for 10 interviews at least you will face 5 to 8 times this question.

What is Final?

Final is as modifiers which can be applicable for classes, methods, variables. If we declare variable as final then it becomes Constant that means reassignment is not possible (we cannot change the value). If you declare a method as final as you cannot override that in child class. If you declare a class as final you cannot extend that class means that inheritance is not possible.

What is Finally?

The finally is blocked, which gets executed whether an exception raised or not and it is used to close the connections such as database connection etc.


try
{

//the risky code 

}
catch{

//handling the code

}
finally{

//clean up code

}

What id finalize?

The finalize() is a method which is always invoked by garbage collector just before destroying an object to perform cleanup activities.

No comments:

Post a Comment

What is Normalization?

Database normalization is a data design and organization process applied to data structures based on rules that help building relational dat...