Class Modifier in Java

digitization, transformation, binary

Class Modifier in Java

This class defines a number of constants and static methods that are used to interpret the integer values returned by the getModifiers() methods of the Field, Method, and Constructor classes. The isPublic(), isAbstract(), and related methods return true if the value of the modifier includes the specified modifier, otherwise, they return false.

In other words, we can use the methods in this class to determine the modifiers used to
declare a class or a member of a class. The constants in the Modifier class specify the bit values used to represent the various modifiers in a modifier value.

Ads code goes here

The constants defined by this class specify the various bit flags used in the value of the modifier. We can use these constants to test for modifiers if you want to perform our own boolean algebra.

The class structure of class Modifier is given as

public class java.lang.reflect.Modifier extends java.lang.Object {
// Default Constructor:
public Modifier();
// Constants
public static final int ABSTRACT;
public static final int FINAL;
public static final int INTERFACE;
public static final int NATIVE;
public static final int PRIVATE;
public static final int PROTECTED;
public static final int PUBLIC;
public static final int STATIC;
public static final int SYNCHRONIZED;
public static final int TRANSIENT;
public static final int VOLATILE;
// Class Methods
public static boolean isAbstract(int mod);
public static boolean isFinal(int mod);
public static boolean isInterface(int mod);
public static boolean isNative(int mod);
public static boolean isPrivate(int mod);
public static boolean isProtected(int mod);
public static boolean isPublic(int mod);
public static boolean isStatic(int mod);
public static boolean isSynchronized(int mod);
public static boolean isTransient(int mod);
public static boolean isVolatile(int mod);
public static String toString(int mod);
}

The details of the class structure are given as follows:

public final static int ABSTRACT;

public final static int ABSTRACT represents a constant that represents the abstract modifier.

public final static int FINAL;

public final static int FINAL represents a constant that represents the final modifier.

public final static int INTERFACE;

public final static int INTERFACE represents a constant that represents the interface keyword.

public final static int NATIVE;

public final static int NATIVE represents a constant that represents the native modifier.

public final static int PRIVATE;

public final static int PRIVATE represents a constant that represents the private modifier.

public final static int PROTECTED;

public final static int PROTECTED represents a constant that represents the protected modifier.

public final static int PUBLIC;

public final static int PUBLIC represents a constant that represents the public modifier.

public final static int STATIC;

public final static int STATIC represents a constant that represents the static modifier.

public final static int SYNCHRONIZED;

public final static int SYNCHRONIZED represents a constant that represents the synchronized modifier.

public final static int TRANSIENT;

public final static int TRANSIENT represents a constant that represents the transient modifier.

public final static int VOLATILE;

public final static int VOLATILE represents a constant that represents the volatile modifier.

public static boolean isAbstract(int mod);

public static boolean isAbstract(int mod) method tests the given modifier value for the ABSTRACT constant.

READ  Class FilterInputStream in Java

This method returns true if the given modifier value includes the abstract modifier; false otherwise.

Parameter
mod – The modifier value to test.

public static boolean isFinal(int mod);

public static boolean isFinal(int mod) method tests the given modifier value for the FINAL constant.

This method returns true if the given modifier value includes the final modifier; false otherwise.

Parameter
mod – The modifier value to test.

public static boolean isInterface(int mod);

public static boolean isInterface(int mod) method tests the given modifier value for the INTERFACE constant.

This method returns true if the given modifier value includes the interface keyword; false otherwise.

Parameter
mod – The modifier value to test.

public static boolean isNative(int mod);

public static boolean isNative(int mod) method tests the given modifier value for the NATIVE constant.

This method returns true if the given modifier value includes the native modifier; false otherwise.

Parameter
mod – The modifier value to test.

public static boolean isPrivate(int mod);

public static boolean isPrivate(int mod) method tests the given modifier value for the PRIVATE constant.

This method returns true if the given modifier value includes the private modifier; false otherwise.

Parameter
mod – The modifier value to test.

public static boolean isProtected(int mod);

public static boolean isProtected(int mod) method tests the given modifier value for the PROTECTED constant.

This method returns true if the given modifier value includes the protected modifier; false otherwise.
Parameter
mod – The modifier value to test.

public static boolean isPublic(int mod);

public static boolean isPublic(int mod) method tests the given modifier value for the PUBLIC constant.

READ  Class CheckedOutputStream in Java

This method returns true if the given modifier value includes the public modifier; false otherwise.

Parameter
mod – The modifier value to test.

public static boolean isStatic(int mod);

public static boolean isStatic(int mod) method tests the given modifier value for the STATIC constant.

This method returns true if the given modifier value includes the static modifier; false otherwise.

Parameter
mod – The modifier value to test.

public static boolean isSynchronized(int mod);

public static boolean isSynchronized(int mod) method tests the given modifier value for the SYNCHRONIZED constant.

This method returns true if the given modifier value includes the synchronized modifier; false otherwise.

Parameter
mod – The modifier value to test.

public static boolean isTransient(int mod);

public static boolean isTransient(int mod) method tests the given modifier value for the TRANSIENT constant.

This method returns true if the given modifier value includes the transient modifier; false otherwise.

Parameter
mod – The modifier value to test.

public static boolean isVolatile(int mod);

public static boolean isVolatile(int mod) method tests the given modifier value for the VOLATILE constant.

This method returns true if the given modifier value includes the volatile modifier; false otherwise.

Parameter
mod – The modifier value to test.

public static String toString(int mod);

public static String toString(int mod) method returns a string that represents the given modifier value. This string contains all of the modifiers specified by the given modifier value.

This method returns a string representation of the given modifier value.

Parameter

mod – The modifier value to represent as a string.

Apart from these Modifier class also has inherited methods from class- Object. They are as follows:

  • clone()
  • finalize()
  • hashCode()
  • notifyAll()
  • wait()
  • wait(long, int)
  • equals(Object)
  • getClass()
  • notify()
  • toString()
  • wait(long)
READ  Class InterruptedIOException in Java

Share and Enjoy !

Leave a Comment

Your email address will not be published. Required fields are marked *