0 votes
1 view
in Java by (4.1k 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 (46.1k 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

Welcome to Intellipaat Community. Get your technical queries answered by top developers !