CS 310, Object-Oriented Programming with Java

Quiz 7, 6 March 2008


  1. A parent class's method m has a throws clause. A child class correctly overrides m; describe the most-general relation between the parent and child methods' throws clauses.


    An exception thrown by the child method cannot be more general than (that is, cannot be an ancestor of) the exception thrown by the parent method (Declaring Checked Exceptions, 562 (7th ed.) or 557 (8th ed.)).

  2. Explain when it's ok to use assertions to check method parameters.


    If a parameter is documented as being valid only under certain conditions (for example, that it be non-negative or non-null), then assertions are an appropriate technique for testing the conditions (Usage Hints for Assertions, page 595 (7th ed.) or Using Assertions for Parameter Checking, page 573 (8th ed.)).


This page last modified on 31 March 2008.