What will be the result of the following code execution?

class A {
    public void process() { 
        System.out.print("A "); 
    }
}

class B extends A {
    public void process() throws RuntimeException {
        super.process();
        if (true) throw new RuntimeException();
        System.out.print("B ");
    }

    public static void main(String[] args) {
        try { 
            ((A)new B()).process(); 
        } catch (Exception e) { 
            System.out.print("Exception "); 
        }
    }
}
Explanation
Although you cannot override a method and add throws Exception, for RuntimeException (unchecked exception) this restriction is not applied.
Java
Java Quiz
Start Quiz

or Read more about Java Quiz

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback