Polymorphism via Interfaces


Review a technique for parsing String as you will need for the PA4.

Dr. Berstein's Stocks example

Use of the parent class to parse what the parent knows and the parent returns a StringTokenizer or Scanner object which essentially gives "the rest" to the child.

Today's notes - Interfaces

Terminology

interface
A Java reserved word that is used to define a set of abstract methods that will be implemented by particular classes.
polymorphism
Many forms - An object-oriented technique by which a reference that is used to invoke a method can result in different methods being invoked at different times. The exact method is determined by the object and not by its reference.

Examples

Lab from Monday - http://java.sun.com/j2se/1.5.0/docs/api/ (Arrays class, sort method)

See HolidayAccount and Driver1.

See TwoPartMeasure, Length, and Driver2.

See book reference page 496 - 498.

Interfaces form an is-a relationship with their implementers.

Interfaces provide a compiler guarantee that a particular method will be implemented.

See Bernstein notes with examples


CS 239 - Spring 2006
Department of Computer Science Nancy Harris Home Page Current Classes Link