Javatpoint Logo
Javatpoint Logo

Java Class getFields() Method

The 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.

Syntax

Parameter

NA

Returns

An array of field object.

Throws

SecurityException.

Example 1

Test it Now

Output:

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 2

Test it Now

Output:

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





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA