I have class that throws higher checked exception in overridden method. I know it is not allowed, but why this code works?
package personaltestlevel1;
public class OverrideExcept {
    public static void main(String args[]) {
        S1 s = new S2();
        try
        {
        s.show(); 
        }catch (NullPointerException e){
        System.out.printf(e.getMessage());
        }
    }  
}
class S1{
    public  void show() throws  NullPointerException {
        try 
        {
        System.out.println("not overriden");
        }catch (Exception e){
        throw new NullPointerException();
        }
    }
}
class S2 extends S1{
    public  void show() throws  RuntimeException {
        try
        {
        System.err.println("overriden");
        }catch (Exception e){
        throw new RuntimeException();}
    }
}
I have updated my sample with checked exception - it works anyway.
 
     
    