valdrus (valdrus) wrote in java_faq,
valdrus
valdrus
java_faq

What is the difference between final, finally and finalize?

o final - declare constant
o finally - handles exception
o finalize - helps in garbage collection

Variables defined in an interface are implicitly final.

A final class can't be extended i.e., final class may not be subclassed. This is done for security reasons with basic classes like String and Integer. It also allows the compiler to make some optimizations, and makes thread safety a little easier to achieve.

A final method can't be overridden when its class is inherited. You can't change value of a final variable (is a constant).

finalize() method is used just before an object is destroyed and garbage collected.

finally, a key word used in exception handling and will be executed whether or not an exception is thrown. For example, closing of open connections is done in the finally method.
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your IP address will be recorded 

  • 0 comments