Java Enum toString() Method

The toString() method of Enum class returns the name of this enum constant, as the declaration contains.

The toString() method can be overridden, although it's not essential.

Syntax

Parameters

NA

Override:

The toString() method of Enum class overrides the toString() method of Object class.

Return Value

The toString() method returns this enum constant's name.

Example 1

Output:

Seven Planets :
1 Mercury
2 Venus
3 Earth
4 Mars
5 Jupiter
6 Uranus
7 Neptune

Example 2

Output:

Enter your positon:
Second
Congratulation! You have won a Silver medal.

Example 3

Output:

Enter your grade
C
Good
You scored above 70