Difference between final, finally and finalizeThe final, finally, and finalize are keywords in Java that are used in exception handling. Each of these keywords has a different functionality. The basic difference between final, finally and finalize is that the final is an access modifier, finally is the block in Exception Handling and finalize is the method of object class. Along with this, there are many differences between final, finally and finalize. A list of differences between final, finally and finalize are given below:
Java final ExampleLet's consider the following example where we declare final variable age. Once declared it cannot be modified. FinalExampleTest.java Output: In the above example, we have declared a variable final. Similarly, we can declare the methods and classes final using the final keyword. Java finally ExampleLet's see the below example where the Java code throws an exception and the catch block handles that exception. Later the finally block is executed after the try-catch block. Further, the rest of the code is also executed normally. FinallyExample.java Output: Java finalize ExampleFinalizeExample.java Output: |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India