Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Notes on ENUM Function in Java Programming

Rating
-
Sold
-
Pages
4
Uploaded on
08-09-2023
Written in
2023/2024

Notes on ENUM Function in Java Programming

Institution
Course

Content preview

ENUM NOTES:-

The Enum in Java is a data type which contains a fixed set of constants.
Java Enums can be thought of as classes which have a fixed set of constants
(a variable that does not change). The Java enum constants are static and
final implicitly. We can define an enum either inside the class or outside
the class.
o Enum ensure strong compile type safety
o Enum can be easily used in switch
o Enum can be traversed {through values()}
o Enum can have fields, constructors and methods as it is also class type
o Enum may implement many interfaces but cannot extend any class because it
internally exten$
o Provides separate name space for each enum type as such same enumerated
constant may appea$
o Constants are not compled into client codes hence can be freely add, remove or
reorder the$
Eg. enum Status { PASS, FAIL;}
enum Direction {NORTH , EAST , SOUTH, WEST;}


Example 1.1:-
enum Color {
RED,
GREEN,
BLUE;

// Driver method
public static void main(String[] args)
{
Color c1 = Color.RED;
System.out.println(c1);
}
}


Example 1:-
class EnumExample1{
//defining the enum inside the class
public enum Season { WINTER, SPRING, SUMMER, FALL }
//main method
public static void main(String[] args) {
//traversing the enum
for (Season s : Season.values())
System.out.println(s);
}}


Example 2:-
// Enum Declared
enum Color {
RED,
GREEN,
BLUE;

Written for

Institution
Course

Document information

Uploaded on
September 8, 2023
Number of pages
4
Written in
2023/2024
Type
Class notes
Professor(s)
Ramlal
Contains
All classes

Subjects

$8.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
shreychandra

Get to know the seller

Seller avatar
shreychandra Birla Insitute of Technology
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
2 year
Number of followers
0
Documents
5
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions