Wednesday 9 November 2016

The finalize() Method



o   finalize() method is used to perform some action when an object is destroyed.
o   For example, if an object is holding some non-java resources such as file handle or character font, then such resources must be freed before the object is destroyed.                                                   
o   To add a finalizer to a class, we define the finalize() method.
o   The Java run time call the finalize() method whenever it is about to recycle an object of that class.
o   The finalize() method has the general form:
protected void finalize()
{
    //finalization code
}

The keywordprotected is a specifier that prevent access to finalize() by code defined outside its class.

No comments:
Write comments