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

Can a serialized object be transferred via network?

519


What comes to mind when someone mentions a shallow copy in java?

664


When a byte datatype is used?

571


Explain about anonymous inner classes ?

582


How do you delete a list in java?

536






Can substring create new object?

564


Why isn’t there operator overloading?

599


Difference between notify() method and notifyall() method in java?

553


What do you mean by checked exceptions?

542


What is the difference between preemptive scheduling and time slicing?

595


Detail discussions on JVM, memory management and garbage collector.

560


What is a copy constructor in java?

582


What are singleton services?

495


What are thread groups?

578


if u open login & logout ,how can udisplay the timelogin & logout members ?

1756