

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Implement Switch on Enum in Java
Enum in Java contains a fixed set of constants. They can have fields, constructors and method. It enhances type safety in Java.
The following is an example wherein we are implementing Switch statement on Enumeration in Java −
Example
public class Demo { public static void main(String[] args) { Laptop l = Laptop.Inspiron; switch(l){ case Inspiron: System.out.println("Laptop for home and office use!"); break; case XPS: System.out.println("Laptop for the ultimate experience!"); break; case Alienware: System.out.println("Laptop for high-performance gaming"); break; } } } enum Laptop { Inspiron, XPS, Alienware; }
Output
Laptop for home and office use!
- Related Questions & Answers
- Java Program to Implement switch statement on strings
- How to use an enum with switch case in Java?
- Can you use a switch statement around an enum in Java?
- Explain restrictions on using enum in java?
- Enum in Java
- How to implement switch-case statement in Kotlin?
- Enum Methods in Java
- Enum constructor in Java
- Java switch statement
- Switch Statement in Java
- On/Off Toggle Button Switch in Tkinter
- Comparing enum members in Java
- Java switch statement example
- Enum in a class in Java
- Java Program to implement NOT operation on BigInteger
Advertisements