Friday, February 12, 2010

What is difference between final and finally and finalize?

  1. final keyword can be applied to variables,method,class. 
  2. final variable - You can't reassign/modify values to the variables. final class- You cannot extends(inherit) the class.
  3. final method- You cannot override the final methods.
  1. finally is used in try-catch (i.e exception handling in java).
  2. Each try contain only one finally blocks not more than one.
  3. There is no statement between catch block and try block. It muse execute if exception is occurred or not. Mostly used for memory release (closes connections).

  1. This is method used to release the occupied memory.
  2. finalize() method must be protected or public otherwise compile time error.

No comments:

Post a Comment