what are the differences between final,finally,finalize
methods?

Answer Posted / somi

Final:- It is used in the following three cases:
If the final keyword is attached to a variable then the variable becomes constant i.e. its value cannot be changed in the program.
If a method is marked as final then the method cannot be overridden by any other method.
If a class is marked as final then this class cannot be inherited by any other class.
Finally:- If an exception is thrown in try block then the control directly passes to the catch block without executing the lines of code written in the remainder section of the try block. In case of an exception we may need to clean up some objects that we created. If we do the clean-up in try block, they may not be executed in case of an exception. Thus finally block is used which contains the code for clean-up and is always executed after the try ...catch block.

Finalize:- It is a method present in a class which is called before any of its object is reclaimed by the garbage collector. Finalize() method is used for performing code clean-up before the object is reclaimed by the garbage collector.

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why java is made?

573


Is java hard to learn?

467


When arithmeticexception is thrown?

585


What do you mean by data type?

550


What is string and example?

559






What are the advantages of inner classes?

510


Under what conditions is an object’s finalize() method invoked by the garbage collector?

583


How to display all the prime numbers between 1 and 100

509


What is the difference between stored procedure & function?

554


What is the significance of java packages?

618


What are the advantages of java?

515


What do you understand by java virtual machine?

711


Name container classes in java programming?

599


What is final keyword in java? Give an example.

580


What is Java Reflection API? Why it’s so important to have?

609