The finalize() Method:

The finalize() Method:
Sometimes an object will need to perform some action when it is destroyed.java provide a mechanism called finalization. By using the finalize() method on the object.

Syntax:
protected void finalize()
{
//finalization code
} 

1.Example for finalize method in java

final class G { 

	// by default it is final. 
	void h() {} 

	// by default it is not final. 
	static int j = 30; 

public static void main(String[] args) 
	{ 
		// See modified contents of variable j. 
		j = 36; 
		System.out.println(j); 
	} 
} 
OUTPUT:
36
Translate »