Java Class getDeclaredFields() Method

The getDeclaredFields() method of java Class class returns an array of field objects representing all the fields defined in this class object. If no filed is declared, then it returns an array of length 0.

Syntax

Parameter

NA

Returns

An array of field object.

Throws

Security Exception

Example 1

Test it Now

Output:

Field (1)long ClassgetDeclaredFieldsExample1.l
Field (2)int ClassgetDeclaredFieldsExample1.i
Field (3)java.lang.String ClassgetDeclaredFieldsExample1.p

Example 2

Test it Now

Output:

Field (1)long ClassgetDeclaredFieldsExample2.l
Field (2)int ClassgetDeclaredFieldsExample2.i
Field (3)java.lang.String ClassgetDeclaredFieldsExample2.p
Field (4)float ClassgetDeclaredFieldsExample2.f
Field (5)boolean ClassgetDeclaredFieldsExample2.b

Next TopicJava Class




Latest Courses