Lecture 39, CS 302-7 and 8, April 27

  1. Various things
    1. Program 4

                                                               i.     Partners - by Friday, 5/4

  1. Review:
    1. Using Javadocs

                                                               i.     Why emphasize now?  Because you need to use it for Program 4

    1. Finally blocks

                                                               i.     Comes after a try{} or a catch(){}

1.    Two ways…

                                                             ii.     Always executes

                                                            iii.     Useful for closing scanners, printwriters, etc

                                                           iv.     Make sure to think about variable scope when using

1.    Reminder – {} blocks signify nested scope boxes

    1. Exception philosophy

                                                               i.     Creating checked vs unchecked exceptions

  1. Exception hierarchy
    1. RuntimeException vs Exception
  2. Build our own Exceptions
    1. Extend either Exception or RuntimeException

                                                               i.     Exception – checked

                                                             ii.     RuntimeException - unchecked

    1. InputVerify.java
    2. ContainsA4Exception
    3. InputTooShortException
  1. Preview of what’s coming - Class hierarchy
    1. Inheritance

                                                               i.     Relationship between classes

                                                             ii.     Ultimate goal – save us time/effort

    1. Superclasses and subclasses

                                                               i.     Other terms - parents/children

                                                             ii.     Example: Vehicle/car

    1. Extends keyword

                                                               i.     Question – why do we define the inheritance relationship in the child instead of the parent?

                                                             ii.     Answer – what if you add your own child class – would you want to have to change the parent?

    1. Substitution principle

                                                               i.     If your code calls for a superclass, you can use one of its subclasses.

1.    Example – vehicle/car

2.    Code example – IOException, FileNotFoundException

                                                             ii.     More specific classes can still use methods from their parent classes

1.    Example with exceptions – printStackTrace, getMessage

  1. Homework – For Monday – Read ch. 9.1-9.3