Javatpoint Logo
Javatpoint Logo

Java Enum clone() Method

The clone() method of Enum class throws CloneNotSupportedException. This method ensures that enums cannot be cloned, which helps to maintain their "singleton" property.

Syntax

Override

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

Return Value

The clone() method doesn't returns anything.

Throws

The clone() method throws CloneNotSupportedException if the object's class does not support the Cloneable interface. Subclasses that overriding this method can also throw CloneNotSupportedException exception to show that an instance cannot be cloned.

Example 1

Test it Now

Output:

People with Red as their favourite colour are generally wiser.

Example 2

Test it Now

Output:

Maruti Car models till yet:
MarutiI launched in 2010 year.
MarutiII launched in 2013 year.
MarutiIII launched in 2016 year.
Next TopicJava Enum



Help Others, Please Share

facebook twitter pinterest