🎴 Flashcard Mode
programming languages Online Quiz - 20
public class test08 { public static void main(String[] args) { try{ A a = new B(); a.show(); }catch (Exception e){ } } }class A{ void show() throws FileNotFoundException{ System.out.println("This is the super class"); }}class B extends A{ void show() throws Exception{ System.out.println("This is the inherited class"); }}What will be the output?
This code fails to compile because of incompatible exception declarations in method overriding. When overriding a method, the subclass method cannot throw a broader checked exception than the parent class method. Here, the parent method throws FileNotFoundException, but the child class method throws Exception, which is broader. This violates Java's overriding rules and results in a compile-time error.