Name: ____________________________________________________ Alpha: _____________________

Describe help received: _________________________________________________________________

  1. [20pts] Consider the example code from the "Getting data in and out" section of this lesson's notes. What's the difference between the example as it is presented, versus a modified version in which the call t.start(); is replaced with;? Your answer should include
  2. [20pts] One way to create threads is to extend the Thread class, overriding the run() method to do whatever your thread is supposed to do, then instantiate an object of your new class type, and call its start() method. Another way is to create a class that implements the Runnable interface . From the API documentation: "A class that implements Runnable can run without subclassing Thread by instantiating a Thread instance and passing itself in as the [target argument to the Thread constructor]."

    Take the Example code from the "Getting data in and out" section of this lesson's notes, and rewrite it so that Foo implements Runnable rather than extending Thread.

    □ check to verify that you actually compiled and ran the modified code.

    Write down the two lines of the program that you actually had to change to change the program to implement Runnable rather than extend Thread:

  3. [10pts] What is the big reason it's important to have the option to implement the Runnable interface rather than extending the Thread class?
  4. [50pts] OOP Review: Duplicating code is a sin in any programming language. Duplicating data (except for backup purposes) is likewise a sin. In Object Oriented Programming, when we see duplicate code or data in two classes, we usually look for an opportunity to common base class for the two, and pull the duplicated code and data into that new parent class. Note that this sometimes requires adding some get-er methods to the parent class to allow access to the data that's now encapsulated in the new parent class. The program below has some glaring instances of duplication of data and code. Your job is to fix this in a nice object oriented way.
    Turn In a codeprint printout of your solution along with a screen capture of it running.