---
title: "What is the difference between final, finally and finalize?"  
description: "What is the difference between final, finally and finalize?"  
author: "Amit Singh"  
published: 2011-05-07  
updated: 2020-09-22  
canonical: https://www.mindstick.com/interview/859/what-is-the-difference-between-final-finally-and-finalize  
category: "java"  
tags: ["java"]  
reading_time: 2 minutes  

---

# What is the difference between final, finally and finalize?

o **final** - declare constant\
o **finally** - handles exception\
o **finalize** - helps in garbage collection

Variables defined in an interface are implicitly final. A final class can’t be extended i.e., final class may not be subclassed. This is done for security reasons with basic classes like String and Integer. It also allows the compiler to make some optimizations, and makes thread safety a little easier to achieve. A final method can’t be overridden when its class is inherited. You can’t change value of a final variable (is a constant). finalize() method is used just before an object is destroyed and garbage collected. finally, a key word used in exception handling and will be executed whether or not an exception is thrown. For example, closing of open connections is done in the finally method.

## Answers

### Answer by mayur kohli

final is a keyword used to declare constants. \
finally block is used in an exception handling.whether there is an exception or not in try block in , finally block will be executed.we used to provide the code like like deallocating resource finalize method will be called by garbage collector to remove the object from memory if it no longer has been used.we can call it explicitely ,but we are not sure that it will remove an object.Read More :- the distinction between final, finally and finalize method

### Answer by Amit Singh

o **final** - declare constant\
o **finally** - handles exception\
o **finalize** - helps in garbage collection

Variables defined in an interface are implicitly final. A final class can’t be extended i.e., final class may not be subclassed. This is done for security reasons with basic classes like String and Integer. It also allows the compiler to make some optimizations, and makes thread safety a little easier to achieve. A final method can’t be overridden when its class is inherited. You can’t change value of a final variable (is a constant). finalize() method is used just before an object is destroyed and garbage collected. finally, a key word used in exception handling and will be executed whether or not an exception is thrown. For example, closing of open connections is done in the finally method.


---

Original Source: https://www.mindstick.com/interview/859/what-is-the-difference-between-final-finally-and-finalize

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
