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

Answer Posted / jayakrishnan.p

final is used for making a class no-subclassable, and making
a member variable as a constant which cannot be modified.
finally is usually used to release all the resources
utilized inside the try block. All the resources present in
the finalize method will be garbage collected whenever GC is
called. Though finally and finalize seem to be for a similar
task there is an interesting difference here.This is because
the code in finally block is guaranteed of execution
irrespective of occurrence of exception, while execution of
finalize is not guarenteed.finalize method is called by the
garbage collector on an object when the garbage collector
determines that there are no more references to the object.

Is This Answer Correct ?    168 Yes 17 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why 1 is not a prime number?

787


Say you want to store the information about a number of pets in an array. Typical information that you could store for each pet (where relevant) would be • Breed of animal • Animal's name • Its birth date • Its sex • Whether it has been sterilised or not • When it is due for its next inoculation • When it last had its wings clipped For each type of pet (eg. dog, cat or bird) you would typically define a class to hold the relevant data. Note: You do not need to implement these classes. Just answer the following questions. 3.1.1 What would be the advantage of creating a superclass (eg. Pet) and declaring an array of Pet objects over simply using an array of Objects, storing each of the instances of the different pet classes (eg. Dog, Cat or Bird) in it? 3.1.2 Would you define Pet as a class or as an interface? Why? (2) (2)

1572


Can constructor be synchronized?

743


If I only change the return type, does the method become overloaded?

728


how are methods defined?

791


How does remove work in java?

724


What are format specifiers in java?

814


What is the importance of hashcode() and equals() methods?

791


Can an interface extend another interface?

817


Can we initialize the final blank variable?

818


Can we override singleton class?

736


How many bytes is a string?

831


Explain about anonymous inner classes ?

805


How to compare strings in java?

690


How do you convert string to int in java?

766