Java OCA OCP Practice Question 1970

Question

Which method headers will result in a correct implementation of a finalizer for the following class?

public class Main {
  // (1) INSERT METHOD HEADER HERE ...
  {
    System.out.println("Final curtain");
    super.finalize();
  }
}

Select the two correct answers.

  • (a) void finalize() throws Throwable
  • (b) void finalize() throws Exception
  • (c) void finalize()
  • (d) protected void finalize() throws Throwable
  • (e) protected void finalize() throws Exception
  • (f) protected void finalize()
  • (g) public void finalize() throws Throwable
  • (h) public void finalize() throws Exception
  • (i) public void finalize()
  • (j) private void finalize() throws Throwable
  • (k) private void finalize() throws Exception
  • (l) private void finalize()


(d) and (g)

Note

(a), (b), (c), (j), (k), (l): reduce the visibility of the inherited method.

(e), (f), (h), (i): the call to the finalize() method of the superclass can throw a Throwable, which is not handled by the method.

The Throwable superclass is not assignable to the Exception subclass.




PreviousNext

Related