Field getModifiers() method in Java with Examples
The getModifiers () method of java.lang.reflect.Field used to return the modifiers used for the field object as time of declaration, as an integer. The Modifier class should be used to decode the modifiers.
Syntax:
public int getModifiers()
Parameters: This method accepts accepts nothing.
Return: This method returns the Java language modifiers for the underlying member.
Below programs illustrate getModifiers () method:
Program 1:
// Java program to illustrate // getModifiers () method import java.lang.reflect.Field; import java.lang.reflect.Modifier; public class GFG { // initialize field private static int number; public static void main(String[] args) throws NoSuchFieldException { // get Field object Field field = GFG.class .getDeclaredField("number"); // apply getModifiers() method int modifiers = field.getModifiers(); // print the results System.out.println( Modifier .toString(modifiers)); } } |
private static
Program 2:
// Java program to illustrate // getModifiers () method import java.lang.reflect.Field; import java.lang.reflect.Modifier; public class GFG { // initialize field final static String value = "Geeks"; public static void main(String[] args) throws NoSuchFieldException { // get Field object Field field = GFG.class .getDeclaredField("value"); // apply getModifiers() method int modifiers = field.getModifiers(); // print the results System.out.println( Modifier .toString(modifiers)); } } |
static final
References: https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Field.html#getModifiers–
Recommended Posts:
- Class getModifiers() method in Java with Examples
- Field get() method in Java with Examples
- Field set() method in Java with Examples
- Field getByte() method in Java with Examples
- Field getFloat() method in Java with Examples
- Field getShort() method in Java with Examples
- Field getDouble() method in Java with Examples
- Field isSynthetic() method in Java with Examples
- Field getType() method in Java with Examples
- Field hashCode() method in Java with Examples
- Field getBoolean() method in Java with Examples
- Field equals() method in Java with Examples
- Field getDeclaringClass() method in Java with Examples
- Field getChar() method in Java with Examples
- Field getAnnotation() method in Java With Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

