Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the implementation of an abstract method in Java needs throws someException declaration if the abstract method has it?

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?

like image 751
Yulin Avatar asked Mar 07 '23 10:03

Yulin


1 Answers

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

like image 50
Matt Avatar answered Mar 10 '23 01:03

Matt