Java uses finalize() method for Garbage collection.
Example:
import java.io.*;
public class FinalizeObject extends FileOutputStream
{
// Contructor definition of the FinalizeFileOutputStream class.
public FinalizeFileOutputStream() throws IOException{
super("Sibi Dharan"); // call the super class constructor.
}
public static void main(String[] args) throws IOException
{
// Create object of FinalizeFileOutputStream class.
FinalizeFileOutputStream objOutstream = new FinalizeFileOutputStream();
// finalize() method call.
objOutstream.finalize();
System.out.print("Stream is closed successfully and connection has "+"cleaned up to the file.");
}
}
Example:
import java.io.*;
public class FinalizeObject extends FileOutputStream
{
// Contructor definition of the FinalizeFileOutputStream class.
public FinalizeFileOutputStream() throws IOException{
super("Sibi Dharan"); // call the super class constructor.
}
public static void main(String[] args) throws IOException
{
// Create object of FinalizeFileOutputStream class.
FinalizeFileOutputStream objOutstream = new FinalizeFileOutputStream();
// finalize() method call.
objOutstream.finalize();
System.out.print("Stream is closed successfully and connection has "+"cleaned up to the file.");
}
}
No comments:
Post a Comment