0% found this document useful (0 votes)
10 views

Lecture05a DataTypesEnums PDF

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().

Uploaded by

s_gamal15
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Lecture05a DataTypesEnums PDF

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().

Uploaded by

s_gamal15
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Data

Types
Numeric Representations
See slides

Enum Types in C
See slides

Enum Types in Java


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

You might also like