Facebook Page Twitter Page LinkedIn Page
× Java.lang Package Classes


The java.lang.Class.getModifiers() method is used to return the Java language modifiers for this class or interface, encoded in an integer. The modifiers consist of the Java Virtual Machine's constants for public, protected, private, final, static, abstract and interface; they should be decoded using the methods of class Modifier.

Syntax

public int getModifiers()

Parameters

No parameter is required.

Return Value

Returns the int representing the modifiers for this class.

Exception

NA.

Example:

The below example shows usage of the java.lang.Class.getModifiers() method.

import java.lang.*;
import java.lang.reflect.*;

public class MyClass {
  public static void main(String[] args) {
    MyClass x = new MyClass();
    Class cls = x.getClass();

    //print the modifier for the class
    int i = cls.getModifiers();
    String name = Modifier.toString(i);
    System.out.println("Class Modifier = " + name);
  }
}

The output of the above code will be:

Class Modifier = public

❮ Java.lang - Class