Java Reference
In-Depth Information
You can now import this class in a program using the import statement. For example, you
can use either of the following statements to use the class IntClass in your program:
import jpfpatpd.ch07.primitiveTypeClasses.*;
or
import jpfpatpd.ch07.primitiveTypeClasses.IntClass;
USING A SOFTWARE DEVELOPMENT KIT (SDK)
If you are using an SDK, such as CodeWarrior or J++ Builder, you can place the file
containing the definition of the class in the same directory that contains your program.
You do not need to create a package. However, you can also create a package using the
SDK. In this case, place the appropriate package statement before the definition of the
class, and use the compile command provided by the SDK. (In most cases, you do not
need to specify a subdirectory.) The compiled file will be placed in the appropriate
directory. You can now import the class without adding it to the project.
If you have created a package for your classes, to avoid compilation errors, do not add the
file containing the definition of the class to the project.
Enumeration Types
Chapter 2 defined a data type as a set of values, combined with a set of operations on
those values. It then introduced the primitive data types: int , char , double , and float .
Using primitive data types, Chapter 8 discussed how to design classes to create your own
data types. In other words, primitive data types are the building blocks of classes.
The values belonging to primitive data types are predefined. Java allows programmers to
create their own data types by specifying the values of that data type. These are called
enumeration or enum types and are defined using the keyword enum . The values that
you specify for the data types are identifiers. For example, consider the following statement:
enum Grades {A, B, C, D, F};
This statement defines Grades to be an enum type; the values belonging to this type are
A , B , C , D , and F . The values of an enum type are called enumeration or enum constants.
Note that the values are enclosed in braces and separated by commas. Also, the enum
constants within an enum type must be unique.
Similarly, the statement:
enum Sports {BASEBALL, BASKETBALL, FOOTBALL, GOLF,
HOCKEY, SOCCER, TENNIS};
defines Sports to be an enum type and the values belonging to this type, that is, the enum
constants, are BASEBALL , BASKETBALL , FOOTBALL , GOLF , HOCKEY , SOCCER , and TENNIS .
 
 
Search WWH ::




Custom Search