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

Answer Posted / saurabh nigam

The keyword "final" in Java is used in different ways
depending on the context. We can have final methods, final
classes, final data members, final local variables and
final parameters. A final class implicitly has all the
methods as final, but not necessarily the data members. A
final class may not be extended; neither may a final method
be overridden.
Final primitive data members cannot be changed once they
are assigned, neither may final object handle data members
(Vector, String, JFrame, etc.) be reassigned to new
instances, but if they are mutable (meaning they've got
methods that allow us to change their state), their
contents may be changed.
A final class cannot be subclassed. This is done for
reasons of security and efficiency. Accordingly, many of
the Java standard library classes are final,


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

Final is used for making a class no-subclass able, and
making
a member variable as a constant which cannot be modified.
Final is a Modifier


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. Finally is a closed Exception Statement

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.
Finalize is method {remove the memory resource before call
The garbage collection}

Is This Answer Correct ?    11 Yes 10 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What's the difference between an abstract class and interface in java?

806


What is method in java with example?

714


Are true and false keywords?

809


Can I extend singleton class in java?

861


Why do we use bufferedreader?

756


Explain the difference between map and flatmap stream operation?

1048


What is the synchronized method modifier?

882


What is private static class in java?

777


What are void methods?

825


Is array synchronized in java?

830


How many tetrahedral voids are there in bcc?

780


What are the four integer types supported by java?

813


4.1 Supply contracts (in the form of comments specifying pre- and post conditions) for the enqueue() method of the LinkedQueue class given in the Appendix. (2) 4.2 Let Thing be a class which is capable of cloning objects, and consider the code fragment: Thing thing1 = new Thing(); //(1) Thing thing2 = thing1; //(2) Thing thing3 = (Thing) thing1.clone(); //(3) Explain how the objects thing2 and thing3 differ from each other after execution of the statements. (

1659


How do you represent a space in regex java?

751


How many types of java are there?

769