Which ALL are true?
-
A finalizer may NOT be invoked explicitly.
-
The finalize method declared in class Object takes no action
-
super.finalize() is called implicitly by any overriding finalize method
-
The finalize method for a given object will be called no more than once by the garbage collector
-
The order in which finalize will be called on two objects is based on the order in which the two objects became finalizable
B is true because Object's finalize() is empty by default. D is true - GC guarantees finalize is called at most once per object. A is false - you CAN call finalize explicitly. C is false - super.finalize() must be called explicitly. E is false - finalization order is NOT guaranteed.
To answer this question, let's go through each option to understand why it is correct or incorrect:
A. A finalizer may NOT be invoked explicitly. - This option is incorrect because a finalizer can be invoked explicitly using the finalize() method. However, it is generally not recommended to do so.
B. The finalize method declared in class Object takes no action. - This option is correct. The finalize() method declared in the Object class does not perform any specific action. It is an empty method.
C. super.finalize() is called implicitly by any overriding finalize method. - This option is incorrect. The super.finalize() method is not called implicitly by any overriding finalize() method. It needs to be explicitly called if required.
D. The finalize method for a given object will be called no more than once by the garbage collector. - This option is correct. The finalize() method for a given object will be called by the garbage collector at most once. After the finalize() method is called, the object becomes eligible for garbage collection.
E. The order in which finalize will be called on two objects is based on the order in which the two objects became finalizable. - This option is not mentioned in the correct answer. Therefore, it is incorrect. The order in which the finalize() method is called on two objects is not determined by the order in which they became finalizable.
The correct answer is B, D. Option B is correct because the finalize() method declared in class Object takes no action. Option D is correct because the finalize() method for a given object will be called no more than once by the garbage collector.