You can use the getModifiers() method to determine accessibility / modifiers, isAccessible() exists for different purposes.
Go through the documentation for the Modifiers class in java. [ Link] It has the methods needed to determine the visibility of a class member.
isAccessible allows isAccessible to reflect the API for accessing any member at runtime. By calling Field.setAcessible(true) , you disable access checks for this particular instance of the field, only for reflection. Now you can access it, even if it is a closed, protected, or package area, even if the caller is not part of these areas. You still cannot access the field using regular code. The compiler will not allow this.
source share