getDeclaredFieldslength
getDeclaredFields is a method in the Java reflection API, defined by the class java.lang.Class. It returns an array of Field objects representing all fields declared by the class or interface represented by the Class object. This includes public, protected, default (package) access, and private fields, but excludes fields inherited from superclasses.
The length of the array returned by getDeclaredFields, accessed as getDeclaredFields().length, gives the number of fields
In contrast, Class.getFields() returns only public fields and includes those inherited from superclasses, while getDeclaredFields reports
Field[] declared = cls.getDeclaredFields();
When working with reflection, handling potential SecurityException is advisable, since a security manager may deny access