Java Reference
In-Depth Information
S
YNTAX
5.3 Defining an Enumerated Type
accessSpecifier enum TypeName { value
1
, value
2
, . . . }
Example:
public enum FilingStatus {SINGLE, MARRIED}
Purpose:
To define a type with a fixed number of values
204
205
5.4 Using Boolean Expressions
5.4.1 The
boolean
Type
In Java, an expression such as
amount < 1000
has a value, just as the
expression
amount + 1000
has a value. The value of a relational expression is
either
true
or
false
. For example, if
amount
is 500, then the value of
amount < 1000
is
true
. Try it out: The program fragment
double amount = 0;
System.out.println(amount > 1000);
prints
true
. The values
true
and
false
are not numbers, nor are they objects of
a class. They belong to a separate type, called
boolean
. The Boolean type is
named after the mathematician George Boole (1815-1864), a pioneer in the study of
logic.
The
boolean
type has two values:
true
and
false