Atucotuco.cs.indiana.edu% ls -ld *.java -rw-r--r-- 1 dgerman faculty 414 Feb 18 00:28 Peer.java -rw-r--r-- 1 dgerman faculty 173 Feb 18 00:28 Setup.java tucotuco.cs.indiana.edu% cat Peer.java class Peer { String name; Peer(String name) { this.name = name; } void ask(Peer other) { System.out.println(other.report()); } String report() { try { return "For " + this.name + " the time is " + new java.util.Date() + "\n on host " + java.net.InetAddress.getLocalHost() + "\n"; } catch (Exception e) { return "Error... " + e; } } } tucotuco.cs.indiana.edu% cat Setup.java class Setup { public static void main(String[] args) { Peer one = new Peer("Larry"); Peer two = new Peer("Michael"); one.ask(two); two.ask(one); } } tucotuco.cs.indiana.edu% javac *.java tucotuco.cs.indiana.edu% ls -ld * -rw-r--r-- 1 dgerman faculty 986 Feb 18 00:29 Peer.class -rw-r--r-- 1 dgerman faculty 414 Feb 18 00:28 Peer.java -rw-r--r-- 1 dgerman faculty 397 Feb 18 00:29 Setup.class -rw-r--r-- 1 dgerman faculty 173 Feb 18 00:28 Setup.java tucotuco.cs.indiana.edu% java Setup For Michael the time is Wed Feb 18 00:29:52 EST 2004 on host tucotuco.cs.indiana.edu/129.79.245.110 For Larry the time is Wed Feb 18 00:29:52 EST 2004 on host tucotuco.cs.indiana.edu/129.79.245.110 tucotuco.cs.indiana.edu%
Peer
can
report()
its date and host name and ip number
ask(...)
another Peer
for a report
"Any major class you expect to be extended, whether abstract or not, should be the implementation of an interface. Although this approach requires a little more work on your part, it enables a whole category of use that is otherwise precluded. For example [...] "Here's what happens now:
tue0217