Explain final, finalize() and finally?

Answer Posted / janet

final: final key word can be used for class,method and
variables.
A final class cannot be subclassed and it prevents other
programmers from subclassing a secure class to invoke
insecure methods.
A final method can't be overridden.
A final variable can't change from it's initialize value.

finalize(): finalize() method is used just before an object
is destroyed and can be called just prior to garbage
collection.

finally: finally, a key word used in exception
handling,creates a block of code that will be executed
after a try//catch block has completed and before the code
following the try//catch block. the finally block will
execute whether or not an exception is thrown.
For example , if a method opens a file upon exit,then
you will not want the code that closes the file to be
bypassed by the exception-handling mechanism. This finally
keyword is designed to address this contingency.

Is This Answer Correct ?    63 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is .net better than java?

555


Write code of any action class?

548


1.IN CASE OF DYNAMIC METHOD DISPATCH WHY WE USE REFERENCE VARIABLE,WE CAN USE THE DIFFERENT DEFINED OBJECT DIRECTLY TO ACCESS THE DATA MEMBER AND MEMBER FUNCTION OF THAT RESPECTIVE CLASS?WHAT IS THE MAIN FUNCTION OF "REFERENCE VARIABLE" HERE?

3793


What is null data type?

538


What purpose do the keywords final, finally, and finalize fulfill?

614






What is a top level class in java?

537


What is string example?

597


What are latest features introduced with java 8?

593


Write a program in java to calculate the difference between the sum of the odd level and even level nodes of a binary tree.

532


Difference between object instantiation and construction ?

582


What is size () in java?

552


How are this() and super() used with constructors in java programming?

572


Why we use multi threading instead of multiprocessing?

576


What are operators and its types?

575


What is the purpose of the finally clause of a try-catch-finally statement in java programming?

511