
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
Can we extend an enum in Java?
No, we cannot extend an enum in Java. Java enums can extend java.lang.Enum class implicitly, so enum types cannot extend another class.
Syntax
public abstract class Enum> implements Comparable, Serializable { // some statements }
Enum
- An Enum type is a special data type which is added in Java 1.5 version.
- An Enum is used to define a collection of constants, when we need a predefined list of values which do not represent some kind of numeric or textual data, we can use an enum.
- Enums are constants and by default, they are static and final. so the names of an enum type fields are in uppercase letters.
- Public or protected modifiers can only be used with a top-level enum declaration, but all access modifiers can be used with nested enum declarations.
Example
enum Country { US { public String getCurrency() { return "DOLLAR"; } }, RUSSIA { public String getCurrency() { return "RUBLE"; } }, INDIA { public String getCurrency() { return "RUPEE"; } }; public abstract String getCurrency(); } public class ListCurrencyTest { public static void main(String[] args) { for (Country country : Country.values()) { System.out.println(country.getCurrency() + " is the currecny of " + country.name()); } } }
Output
DOLLAR is the currecny of US RUBLE is the currecny of RUSSIA RUPEE is the currecny of INDIA
- Related Articles
- Can Enum extend any class in java?
- Can we extend interfaces in Java? Explain?
- Can we create an enum with custom values in java?
- Can we define an enum inside a class in Java?
- Can we define an enum inside a method in Java?
- Can we have variables and methods in an enum in Java?
- Can we have integers as elements of an enum in Java?
- Can an interface in Java extend multiple interfaces?
- Can an interface extend multiple interfaces in Java?\n
- Can Enum implements an interface in Java?\n
- How we can extend multiple Python classes in inheritance?
- How can we get the name of the Enum constant in Java?\n
- Can you use a switch statement around an enum in Java?
- Can you extend a static inner class in Java?
- How do we use an enum type with a constructor in Java?\n

Advertisements