ClassNotFoundException
is a checked exception - and you can't declare that a method override will throw any checked exceptions that the method it's overriding doesn't declare.
From section 8.4.8.3 of the JLS:
A method that overrides or hides another method, including methods that implement abstract methods defined in interfaces, may not be declared to throw more checked exceptions than the overridden or hidden method.
Consider, for example:
Test t = new MyTest();
t.demo();
There's nothing in that code to indicate that ClassNotFoundException
will be thrown, because Test.demo()
doesn't declare that it will be thrown. However, the whole point of checked exceptions is that the caller is forced to consider what to do with them (catch them or declare that they might throw the exception too). The ability to override a method and declare that it throws a new checked exception not covered by the original method declaration would make a nonsense of that.