Amazon Interview Question
Software Engineer / DevelopersFinal declares a variable to be non-changing. Finally is used following a try/catch block - anything inside "finally" will be called whether an exception was thrown from the block or not. Finalize is a calback you can define on a class which will be fired right before the garbage collector collects the object.
1)final
- badalrocks January 20, 2009When applied to variable(primitive): The value of the variable cannot change.
When applied to variable(reference): The reference variable cannot point to any other object on the heap.
When applied to method: The method cannot be overridden.
When applied to class: The class cannot be subclasses.
2)finally
There is an optional finally block after the try block or after the catch block. Statements in the finally block will always be executed (except if JVM exits from the try block). finally block is used to write the clean up code.
3)finalize
This is the method the JVM runs before running the garbage collector.