Java Reference
In-Depth Information
public boolean
get()
{
return
flag;
}
public void
set(
boolean
f)
{
flag = f;
}
public
String toString()
{
return
(String.valueOf(flag));
}
}
This section describes how to use the classes introduced in the previous section.
The
class
IntClass
can be used in two ways. One way is to keep the file
IntClass.java
and the program in the same directory. First, compile the file
IntClass.java
, then compile the program.
The second way is to first create a package, and then put this class in that package. For
example, you can create the package:
jpfpatpd.ch07.primitiveTypeClasses
and put the class in this package.
In this case, you place the statement:
package
jpfpatpd.ch07.primitiveTypeClasses;
before the definition of the
class
IntClass
.
The
class
IntClass
definition is in the file
IntClass.java
. We need to compile this file
and place the compiled code in the directory:
jpfpatpd.ch07. primitiveTypeClasses
.
To do so, we execute the following command at the command line:
javac -d c:\jre1.7.0\lib\classes IntClass.java
The file
IntClass.class
is now placed in the subdirectory
jpfpatpd\ch07
\primitiveTypeClasses
of the directory
c:\jre1.7.0 \lib\classes
.
On the other hand, the command:
javac IntClass.java
places the file
IntClass.class
in the subdirectory
jpfpatpd\ch07\primitive TypeClasses
of the same directory. Note that the system automatically creates the subdirectory
jpfpatpd\ch07\primitiveTypeClasses
if it does not exist.
Search WWH ::
Custom Search