WHAT IS THE DIFFERENCE BETWEEN FINAL, FINALLY AND FINALIZE?

Amit Singh

Total Post:565

Points:2825
Posted by  Amit Singh
Java 
 4658  View(s)
Ratings:
Rate this:
  1. Amit Singh

    Post:565

    Points:2825
    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.

  1. mayur kohli

    Post:1

    Points:5
    What is the difference between final, finally and finalize?

    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.

      Modified On Sep-12-2017 02:04:00 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!