5

In the superclass I have:

abstract someMethod() throws someException;

In the subclass I have:

someMethod(){/*do something*/}

Is it ok to do this without a throws someException declaration? Is it that the throws someException declaration is there by default without adding it explicitly?

Matt
  • 2,063
  • 1
  • 14
  • 35
Yulin
  • 1,163
  • 1
  • 7
  • 10
  • 3
    If an implementation doesn't throw an exception, it doesn't have to declare it. Not explicitly or implicitly. – shmosel Dec 06 '17 at 02:46
  • 1
    This question falls squarely into the "try it and see if it works" category. Or in this case, "try it and see if it compiles". – Dawood ibn Kareem Dec 06 '17 at 03:11
  • 1
    @Dawood, I known it compiles, only don't know it compiles because the `throws exception` is add automatically or not necessary. – Yulin Dec 06 '17 at 11:08

1 Answers1

7

Your implementation doesn’t have to throw any exceptions. However, it can only throw checked exceptions specified in the abstract class.

shmosel
  • 49,289
  • 6
  • 73
  • 138
Matt
  • 2,063
  • 1
  • 14
  • 35