Multiple choice technology programming languages

The following code throws an exception. public class ContainerClass { public void draw() throws IOException { // additional code to write values to file. system.out.println("This container was drawn and saved to file."); return true; } } What code overrides this method? (Note that Exception itself is a superclass of IOException)

  1. 1 public class Cup extends ContainerClass {

  2. 2 public class Basket extends ContainerClass {

  3. 3 public class Caldron extends ContainerClass {

  4. 4 public class Bag extends ContainerClass {

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

The overriding method cannot throw checked exceptions broader than those declared in the overridden method. Since ContainerClass.draw() throws IOException, the override must throw IOException or narrower. Option B shows Basket.draw() throwing IOException - valid. Options with no throws clause or broader exceptions are invalid.