Java Challenge #8: Enums Implementing Interfaces

Enums, do you really master them? Can you tell me if it’s going to compile? If not, explain why. If so, write the result.

Try to solve this challenge before seeing the answer below.


Answer: The first thing to observe is the implementation of the interface Invoker on the Enum. It’s not very common to do this, but it’s possible. When we access the Enum reference of the reference it does not make a difference. The invokeShenLong() method will be invoked in the same way bringing all the Enums declared on DragonBalls. When we enter in the loop, we are not using brackets ({}) on the “if” command. This means that only one line will be executed.

Conclusion: Until the Enums are equaled, the looping will continue. In the end, the iterated Enums will be FIFTH and equal to one another.

The output will be:
Same dragon ball

Java Challenge #8: Enums Implementing Interfaces

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s