Enum getClass() in Java

getClass(): This method is available in java.lang.Object class of Java.

Syntax:

Class<? extends Colour> java.lang.Object.getClass()

This method returns the runtime class of this Object. The returned Class object is the object that is locked by static synchronized methods of the represented class.

Parameters: NA

Returns: The Class object that represents the runtime class of this object.

Exceptions: NA

Approach

Java

enum Colour {
    RED, GREEN, GRAY, ORANGE
}

public class EnumgetClass {
    public static void main(String[] args) {

        System.out.println(Colour.RED.getClass());
    }
}

Output:

class com.example.Enum.Colour


No comments:

Post a Comment