Mastering Java: The Ultimate Quiz for 'Thinking in Java'

Disable ads (and more) with a membership for a one time $2.99 payment

Mastering Java: The Ultimate Quiz for 'Thinking in Java'. Dive deep into Java with multiple-choice questions. Challenge yourself with quiz questions designed to test and improve your understanding of the 'Thinking in Java' book. Get ready for your exam!

Practice this question and more.


Which class will not throw a compilation error if extended by adding a new checked exception to a method signature?

  1. A class that implements an interface

  2. A final class

  3. An abstract class

  4. None, adding a new checked exception is always an error

The correct answer is: An abstract class

Classes that implement an interface (A) will also throw a compilation error due to the need for the method to be implemented. Final classes (B) cannot be extended, so adding a checked exception to their method signature would not be possible. Abstract classes (C) allow for flexibility in method signatures and do not throw compilation errors when a new checked exception is added. Option D states that none of the classes will throw a compilation error, which is incorrect as stated in the question.