Java Class getFields() MethodThe getFields() method of java Class returns an array containing field objects representing all the accessible public fields of the class or interface represented by this Class object otherwise if no field is present then it returns an array of length 0. SyntaxParameterNA ReturnsAn array of field object. ThrowsSecurityException. Example 1Test it NowOutput: All Fields = public static final int java.awt.Label.LEFT public static final int java.awt.Label.CENTER public static final int java.awt.Label.RIGHT public static final float java.awt.Component.TOP_ALIGNMENT public static final float java.awt.Component.CENTER_ALIGNMENT public static final float java.awt.Component.BOTTOM_ALIGNMENT public static final float java.awt.Component.LEFT_ALIGNMENT public static final float java.awt.Component.RIGHT_ALIGNMENT public static final int java.awt.image.ImageObserver.WIDTH public static final int java.awt.image.ImageObserver.HEIGHT public static final int java.awt.image.ImageObserver.PROPERTIES public static final int java.awt.image.ImageObserver.SOMEBITS public static final int java.awt.image.ImageObserver.FRAMEBITS public static final int java.awt.image.ImageObserver.ALLBITS public static final int java.awt.image.ImageObserver.ERROR public static final int java.awt.image.ImageObserver.ABORT Example 2Test it NowOutput: public static final java.math.BigDecimal ClassgetFieldsExample2$Interface1.dnum public static final java.math.BigInteger ClassgetFieldsExample2$Interface1.Inum public static final java.math.BigDecimal ClassgetFieldsExample2$Interface1.dnum2 public java.lang.String ClassgetFieldsExample2$SuperClass.str public java.math.BigInteger ClassgetFieldsExample2$SuperClass.iinum public java.math.BigInteger ClassgetFieldsExample2$SuperClass.inum3 public double ClassgetFieldsExample2$SuperSuperClass.dbl Next TopicJava Class |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India