Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (4k points)

I want to take an existing enum and add more elements to it as follows:

enum A {a,b,c}

enum B extends A {d}

/*B is {a,b,c,d}*/

Is this possible in Java?

1 Answer

0 votes
by (46k points)

It's not possible in Java. Apart from anything else, d would then probably be an instance of A (given the standard idea of "extends"), but users that only knew of A wouldn't understand it - which takes the point of an enum is a well-known set of values.

If you could explain to me more about how you want to practice this, I could recommend alternative resolutions.

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...