Difference between final & finally & finalize keyword?

Difference between final & finally & finalize keyword?

Difference between final & finally & finalize keyword?

Difference between final & finally & finalize keyword?

The keyword final is an access modifier, finally is a block and finalize is a method. The keyword final is applicable to the classes, variables and methods of the classes finally is a block associated with the try catch block that is used to handle exceptions, finalize is a method that operates only on objects. The variable once declared as final becomes constant and can’t be reassigned again, a method declared as final can’t be overridden, and class once declared as final can never be inherited. The finally block is used to clean up the resources utilised by try and catch block. The finalize method is used to clean up the resources used by an object before the object is destroyed.

Final

  • Final is a modifier applicable for classes, methods, and variables.
  • If a class declared as final then we can extend that class i.e. We can create a child class for that class i.e. Inheritance is not possible for final classes.
  • If a method is final then we can’t override that method in the child class.
  • If a variable declares as final then we can’t perform re-assignment for that variable.
  • If you make a class final means it cannot be subclassed. Making a class final automatically makes all its method final and this is sometimes required due to security reason, This is one of the reasons Why String is final in Java. In short, final is not related at all with either finally or finalize keyword. final keyword also helps to write Immutable classes which are critical for designing thread-safe multi-threading system and reducing the amount of synchronization.
Difference between final & finally & finalize keyword? The keyword final is an access modifier, finally is a block and finalize is a method. The keyword final is applicable to the classes, variables and methods of the classes finally is a block associated with the try catch block that is used to handle exceptions, finalize is a method that operates only on objects. The variable once declared as final becomes constant and can’t be reassigned again, a method declared as final can’t be overridden, and class once declared…

Review Overview

User Rating: 4.65 ( 2 votes)

One comment

Leave a Reply

Your email address will not be published. Required fields are marked *

*