Which two are true? (Choose two.)

  1. A finalizer may NOT be invoked explicitly.

  2. The finalize method declared in class Object takes no action.

  3. super.finalize() is called implicitly by any overriding finalize method.

  4. The finalize method for a given object will be called no more than

  5. The order in which finalize will be called on two objects is based on


Correct Option: B,D

AI Explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) A finalizer may NOT be invoked explicitly. This option is incorrect because a finalizer method can be invoked explicitly using the finalize() method. However, it is generally not recommended to invoke the finalizer method explicitly.

Option 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 by default. Subclasses can override this method to define their own finalization logic.

Option C) super.finalize() is called implicitly by any overriding finalize method. This option is incorrect. In Java, the finalize method does not automatically call super.finalize(). If a subclass overrides the finalize method, it has to explicitly call super.finalize() if it wants to execute the finalization logic of the superclass.

Option D) The finalize method for a given object will be called no more than once. This option is correct. The finalize method is called by the garbage collector before reclaiming the memory occupied by an object. Once the finalize method is called for an object, it will not be called again for the same object. This ensures that the finalization logic is executed only once.

Option E) The order in which finalize will be called on two objects is based on This option is incomplete and does not provide a complete statement. It is not clear what the order of finalization is based on. Therefore, this option is incorrect.

The correct answers are B and D. Option B is correct because the finalize method declared in the Object class takes no specific action. Option D is correct because the finalize method for a given object will be called no more than once.

Therefore, the correct answer is B and D.

Find more quizzes: