Java Reference
In-Depth Information
(separated by commas in the extends part of the definition), and the new interface con-
tains a combination of all its parent's methods and constants.
In interfaces, the rules for managing method name conflicts are the same as for classes
that use multiple interfaces; methods that differ only in return type result in a compiler
error message.
Creating an Online Storefront
To explore all the topics covered up to this point today, the Storefront application uses
packages, access control, interfaces, and encapsulation. This application manages the
items in an online storefront, handling two main tasks:
Calculating the sale price of each item depending on how much of it is presently in
stock
n
Sorting items according to sale price
n
The Storefront application consists of two classes, Storefront and Item . These classes
will be organized as a new package called org.cadenhead.ecommerce , so the first task is
to define a folder structure on your system where this package's classes will be stored.
The JDK and other Java development tools look for packages in the folders listed in the
system's Classpath , taking the package name into account. To prepare for this project,
create a new folder that will be the root folder for all packages that you create. On my
Windows XP system, I've designated c:\dev\java for this purpose.
This folder should be added to your system's Classpath setting. For instructions on how
to do this, read Appendix A.
When you create a new package, create the corresponding folder structure inside your
package folder. The structure for this project should be org\cadenhead\ecommerce .
On my system, I created c:\dev\java\org\cadenhead\ecommerce to hold its class files.
6
After you have created a folder for the package and added it to your Classpath , create
Item.java from Listing 6.2.
LISTING 6.2
The Full Text of Item.java
1: package org.cadenhead.ecommerce;
2:
3: import java.util.*;
4:
5: public class Item implements Comparable {
6: private String id;
Search WWH ::




Custom Search