Consider the following program:
class Exception1 extends Exception {} interface Printable { public abstract void print() throws Exception1; } interface Walkable { public void walk(); } abstract class Shape { public void print() { System.out.print("cannot print "); } // LINE A } class Robot extends Shape implements Printable, Walkable { // LINE B public void walk() { System.out.print("walk "); } } public class Main { public static void main(String []args) { Robot pingu = new Robot(); pingu.walk();/* w w w. j a va 2s. c om*/ pingu.print(); } }
Which one of the following options correctly describes the behavior of this program?
print()
does not declare to throw Exception1.print()
is not defined and hence need to declare it abstract.d)
In order to override a method, it is not necessary for the overridden method to specify an exception.
However, if the exception is specified, 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).