Multiple choice

class sample9 { public static void main(String []args) { sample s=new sample(); s.walk(); s.fly(); } } class CannotFlyException extends Exception { } interface Bird { public abstract void fly() throws CannotFlyException; } interface Bipe { public void walk(); } abstract class noFlyer
{ public void fly() { System.out.print("cannot fly" );//LINE A } } class sample extends noFlyer implements Bird, Bipe //LINE B { public void walk() { System.out.print("walk" ); } }

Which of the following options is the output of this program?

  1. Compiler error in line with comment LINE A because fly() does not declare to throw CannotFlyException.

  2. Compiler error in line with comment LINE B because fly() is not defined and hence need to declare it abstract.

  3. It crashes after throwing the exception CannotFlyException.

  4. Walk cannot fly

  5. None of the above

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

To override a method, mentioning exception is not important but if you specify Exception, then the specified exception must be the same or a subclass of the specified exception in the method defined in the super class (or interface).