Javatpoint Logo
Javatpoint Logo

Java Class getField() Method

The getField() method of java Class class returns a field object which represents the public member field of the class or interface represented by this Class object. A string specifying the simple name of the desired field is passed as the parameter.

Syntax

Parameter

name - the field name

Returns

Field object.

Throws

NoSuchFieldException , NullPointerException , SecurityException

Example 1

Test it Now

Output:

Field got  =
 field found: public java.lang.String ClassgetFieldExample1.str

Example 2

Test it Now

Output:

public int ClassgetFieldExample2.num
int

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