Lecture 40, CS 302-6, December 07

  1. Various things
    1. Program 4

                                                               i.     Grading:

1.    15% Object oriented structure, 10% Commenting

                                                             ii.     Tip – figuring out if a move is valid and flipping the pieces is probably the toughest part.  If you get stuck, try working on the save and load options

                                                            iii.     Partners - by Friday, 12/9

    1. Extra consulting hours start Friday, continue through weekend
    2. Final exam info posted

                                                               i.     Sample questions

                                                             ii.     Last spring’s exam

  1. Review:
    1. Building our own exceptions

                                                               i.     Extends clause

                                                             ii.     public class <className> extends <className>

                                                            iii.     Extend either Exception or Runtime Exception, depending on whether you want it to be checked or unchecked.

    1. Class Hierarchy (note – not on final)

                                                               i.     Inheritance – relationship between classes

                                                             ii.     Subclasses/children and Superclasses/parents

                                                            iii.     The role that extends plays in this – defining a subclass

    1. Substitution principle

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

    1. More specific classes can still use methods from their parent classes
  1. Overriding and Overloading
    1. Overriding methods

                                                               i.     Defining the same method in a subclass as a superclass – if we call it from an object of the subclass, it will use the subclass version

    1. Overloading

                                                               i.     Same method name, different parameters

                                                             ii.     Overloading constructors

                                                            iii.     Overloading methods

  1. super
    1. Another reserved word - super
    2. Used for calling methods, constructors, and accessing variables from superclass
    3. Use to access methods from super class that are overridden

                                                               i.     Syntax: super.method(params);

                                                             ii.     Things to be careful about – if calling the same method from the superclass from within a method in the subclass, make sure to use the super keyword – otherwise, you’ll probably end up in an infinite loop

                                                            iii.     Superclass constructors

1.    Can call the superclass constructor from within the subclass constructor

2.    Syntax: super(params);

  1. More vocab:
    1. Dynamic method lookup

                                                               i.     Method calls are determined by type of object, not variable

    1. Polymorphism

                                                               i.     Ask different objects to carry out same task – each does it in its own way

  1. Example – Car, Vehicle, Bike, VehicleTester
  2. Note – material from this part of chapter 9 will not be on the exam
    1. It will, however, come in handy with the extra credit for P4
  3. Homework – For Wednesday – Finish ch 9