When you override a method in child class then the throws clause must be compatible with the overridden method. In your case your Test.demo()
method throws NumberFormatException, ArrayIndexOutOfBoundsException
which are not mandatory for the throws clause because they are RuntimeExceptions
In your MyTest.demo() method you are throwing IndexOutOfBoundsException,ClassNotFoundException
out of which IndexOutOfBoundsException
is a RuntimeException and that is again not mandatory to throw. ClasssNotFoundException
is a checked exception and there is nothing in your parent class demo() method that could match it. hence the error you are getting.
Two options to correct:
- add ClassNotFoundException to your Test.demo()
- remove it from MyTest.demo()
Hope this helps