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
Is .net better than java?
Write code of any action class?
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?
What is null data type?
What purpose do the keywords final, finally, and finalize fulfill?
What is a top level class in java?
What is string example?
What are latest features introduced with java 8?
Write a program in java to calculate the difference between the sum of the odd level and even level nodes of a binary tree.
Difference between object instantiation and construction ?
What is size () in java?
How are this() and super() used with constructors in java programming?
Why we use multi threading instead of multiprocessing?
What are operators and its types?
What is the purpose of the finally clause of a try-catch-finally statement in java programming?