Which statement about the following classes is correct?
class Exception2 extends Exception {} class Printable { public int getSymbol() throws Exception2 { return -1; } // g1 } public class Main extends Printable { public int getSymbol() { return 8; } // g2 public void printData() { try { //from ww w . ja v a 2 s. c o m System.out.print(getSymbol()); } catch { // g3 System.out.print("Unable to read data"); } } }
C.
The code does not compile because the catch block is missing a variable type and name, such as catch (Exception e).
Option C is the correct answer.
Both implementations of getSymbol()
compile without issue, including the overridden method.
A subclass can swallow a checked exception for a method declared in a parent class; it just cannot declare any new or broader checked exceptions.