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

Java 8Object Oriented ProgrammingProgramming

The final keyword can be used with class method and variable. A final class cannot be instantiated, a final method cannot be overridden and a final variable cannot be reassigned.

The finally keyword is used to create a block of code that follows a try block. A finally block of code always executes, whether or not an exception has occurred. Using a finally block allows you to run any cleanup-type statements that you just wish to execute, despite what happens within the protected code.

The finalize() method is used just before object is destroyed and can be called just prior to object creation.

raja
Published on 10-Jan-2018 11:59:28
Advertisements