Java Interview Question

Use this advanced question and answer to prepare for your next Java interview.

If a super class method is throwing RuntimeException, can it be overriden in a subclass method throwing NullPointerException?


In Java, it is possible to override a method with a different throws signature if the base class method only throws Runtime Exception (unchecked exceptions). If the base class method throws checked exceptions, then the subclass method has to have one of the following:

  • Same exception
  • Sub-exception class
  • Runtime exception
  • No exception

Looking for developers?

Want to learn more about Gigster? Enter your email and one of our project engineers will be in touch.