- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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!
Advertisements