Explain difference between final, finally and finalize?

Answers were Sorted based on User's Feedback



Explain difference between final, finally and finalize?..

Answer / vijayakumar chinnnasamy

final:
final keyword can be applied to vairables,method,class.
fianl variable - You can't reassign/modify values to the
vaiables.
final class- You cannt extends(inherit) the class.
final method- You cannt override the final methods.

finally:

finally is used in try-catch (i.e exception handling in
java).
Each try contain only one finally blocks not more than
one.
There is no statement between catch block and try block.
It will be execute if exception is occure or not.
Mostly used for memeory release.

finalize:
This is method used to release the occupied memeory.
finally method must be protected or public otherwise
compile time error.

Is This Answer Correct ?    74 Yes 5 No

Explain difference between final, finally and finalize?..

Answer / ranganathkini

When a class is marked final, it cannot be subclassed. When
a method is marked final, it cannot be overridden by the
subclass. And when a field is marked final, its value once
set, cannot be reset.

finally is the last clause in a try...catch block. It is a
block of statements that is executed irrespective if or if
not an exception was caught in the preceding try block.

finalize is a reserved method in Java, which can be
overridden by classes containing code to release any
expensive resources being held to by the object. Expensive
resources include, native peer objects, file/device/database
connections.

Is This Answer Correct ?    64 Yes 13 No

Explain difference between final, finally and finalize?..

Answer / mukund viswanath vyavhare

Final -it is keyword .It is use for
variables and method.
Finally-it is use to define a block
that is always executed in try
catch and finally stetment.

Is This Answer Correct ?    11 Yes 7 No

Post New Answer

More Core Java Interview Questions

Java.util.regex consists of which classes?

0 Answers  


Which of the following can be referenced by a variable? A. The instance variables of a class only B. The methods of a class only C. The instance variables and methods of a class

2 Answers  


what invokes a threads run() method? : Java thread

0 Answers  


What is the difference in between cpp and java? Can u explain in detail?

0 Answers  


What happens if main method is not static?

0 Answers  






Is it correct to say that due to garbage collection feature in java, a java program never goes out of memory?

0 Answers  


What is the difference between a scrollbar and a scrollpane?

0 Answers  


What are classloaders?

0 Answers  


How many characters is 2 bytes?

0 Answers  


Does 'true' and 'false' are keywords?

5 Answers  


What is an example of a constant variable?

0 Answers  


What is meant by inheritance and what are its advantages?

0 Answers  


Categories