The document discusses different data types including numeric representations and enum types in C and Java. It notes that enum types in Java are full classes that can be used to define a fixed set of constants. Syntax for enums in Java involves using the enum keyword and declaring constants, and enums provide built-in methods like values() and name().
The document discusses different data types including numeric representations and enum types in C and Java. It notes that enum types in Java are full classes that can be used to define a fixed set of constants. Syntax for enums in Java involves using the enum keyword and declaring constants, and enums provide built-in methods like values() and name().
Enumerated
types
are
full
classes
Usage:
when
you
need
a
fixed
set
of
constants
Syntax:
public enum Day { SUNDAY, MONDAY, , SATURDAY; } Or:
public enum Day { SUNDAY(0), MONDAY(10), ; private int code; private Day(int code) { this.code = code; } } Usage:
Day.SUNDAY Convention:
all
Caps
Strongly
typed
so
cannot
assign
arbitrary
integer
values
May
be
used
in
switch
cases
Built-in
methods:
o .values()
returns
an
array
of
values
o .name()
returns
a
string
of
the
enums
name