Monday 16 March 2015

Q 20) Difference Final Finally Finalize.

Final :

     Classes : Cannot be extended.
     Methods : Cannot be used outside of the class.
     Variables: cannot be used outside of the class.
                
               final is a keyword. The variable declared as final should be initialized only once and cannot be changed. And Methods declared as final cannot be overridden.

Finally :
               finally is a keyword in java which is used in exception handling along with try, catch and throws.
                
               finally is a block. The finally block always executes when the try block exits. This ensures that the finally block is executed even if an unexpected exception occurs.

Finalize () :

                finalize is a method in java which is called by the garbage collector. Before an object is garbage collected, the runtime system calls its finalize() method.

No comments:

Post a Comment