Answer Posted / ramanareddy333
every class inherits the finalize() method from
java.lang.Object
the method is called by the garbage collector when it
determines no more references to the object exist
the Object finalize method performs no actions but it may
be overridden by any class
normally it should be overridden to clean-up non-Java
resources ie closing a file
if overridding finalize() it is good programming practice
to use a try-catch-finally statement and to always call
super.finalize() (JPL pg 47-48). This is a saftey measure
to ensure you do not inadvertently miss closing a resource
used by the objects calling class
protected void finalize() throws Throwable {
try {
close(); // close open files
} finally {
super.finalize();
}
}
any exception thrown by finalize() during garbage
collection halts the finalization but is otherwise ignored
finalize() is never run more than once on any object
| Is This Answer Correct ? | 4 Yes | 1 No |
Post New Answer View All Answers
Is assembly language a low level language?
What are variable names?
How finally used under exception handling?
Does java support multiple inheritances?
what are the high-level thread states? : Java thread
What is the default value of local and global variables?
What is tostring () method?
What is your platform?s default character encoding and how to know this?
What is meant by data hiding/encapsulation?
What is a function in programming?
Is void a data type?
How can the checkbox class be used to create a radio button?
What is the list interface?
What are synchronized blocks in java?
Why are constructors used?