A) The finalize method is invoked by JVM at most once in the life of an object. --- True.. because the garbage collection might never happen during the run time of an application at all or might happen . In first case finalize() method is never called, in second case its called just once per object.So yes the method is invoked at most once.
(B) If the finalize method is overriden, the JVM will definitely invoke it. True...finalize method is over ridden so that you can perform final operations like closing connections stuff, just before garbage collection removes objects from memory.
(C) Exceptions thrown by the finalize method are ignored by the garbage collector. True...the gc process continues, only the code in the finalize might be skipped after exception.
(D) Calling System.gc() will definitely call the finalize() method. false...System.gc() can just request garbage collection, not gurantee it, so we cant guarantee that finalize() will run
(E) The finalize method may throw checked exceptions. False...the defination of finalize does not throw checked exceptions...so while overriding it you cannot declare it to throw any checked exceptions either as per the overriding rule. [ April 24, 2007: Message edited by: megha joshi ]
Joined: Mar 16, 2007
My Answer to it is A and (A) True. (B) If the finalize method is overriden, the JVM will definitely invoke it. --False. Since JVM will not definitely invoke a finalize method. (C)false, but I am not sure about this. (D)false. Obvious. (E)true. Since finalize() method in object throw Throwable. SO it can throw Exceptions.
All is well but what goes wrong with this poor option!
(B) If the finalize method is overriden, the JVM will definitely invoke it.
Does anybody know?
Joined: Feb 20, 2007
I think this option is wrong becuase of the word "definately".
We know if the finalize() method is overridden it would be invoked by the JVM if garbage collection is started. But just as garbage collection is not definate, calling the finalize() is not definate and thus calling the overridden version of finalize() is not definate.
I think if the option would be like,
If the finalize() method is overridden, than the JVM can/may invoke it... it would be more True.