Given the following class and interface definitions:
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 "); } }
Select the correct option for this code segment:
Robot pingu = new Robot();
pingu.walk();
pingu.print();
print()
does not declare to throw Exception1print()
is not defined and hence need to declare it abstractd)
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).