Java Programming Home Page: Archive: Message #128

Date: Nov 14 2000 12:50:39 EST
From: "Java Programming" <javaProgramming-owner@listbot.com>
Subject: sw408, Monday Section HW

Hi All,
Here is the code for the Monday class held on 11/13/00.
You are to compile and run the program, then bring the
output to class, as a homework, next week. Please
study the code and try to understand it. Also, you
might learn from altering the program a little.

We will go over the flow of execution next week, in class.

Thanks!

Regards,
 - DL


----------------------------------------------------------------------------------------
---------------------------------------------------------
/*
     Homework 4 - Using an Interface as a Reference Data Type
     This will print a Customer name on a 'bill'
*/

interface Runnable {
     public void run();
}

public class Bill {
     // create an object of data type 'Runnable interface'
     Runnable r;
     // Constructor method
     Bill(Runnable _r) {
          r = _r;
     }
     public void Start() {
          r.run();

     }
}

class Customer implements Runnable {
     // Print customer name
     public void run() {
          System.out.println("J. Doe");
     }
}

class Demo {
     // Execution begins here
     public static void main (String args[]) {
          Bill b = new Bill(new Customer());
               b.Start();
     }
}
// ps, thanks to Kathy for typing this in!