22-12-2009, 09:18 PM | #1 |
Member
Join Date: Dec 2009
Posts: 50
Rep Power: 15 |
difference between final, finally and finalize
|
22-12-2009, 09:19 PM | #2 |
Member
Join Date: Dec 2009
Posts: 50
Rep Power: 15 |
final - declare constant
finally - handles exception 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. |
Bookmarks |
Tags |
java interview question |
|
|