Online Java Compiler By
JavaTpoint.com
//import statements import java.lang.reflect.*; public class ClassgetDeclaredFieldsExample1 { public static void main(String[] args) { try { ClassgetDeclaredFieldsExample1 obj = new ClassgetDeclaredFieldsExample1(); Class class1 = obj.getClass(); Field[] getfields = class1.getDeclaredFields(); for(int i = 0; i < getfields.length; i++) { System.out.println("Field (" +(i+1)+ ")" + getfields[i].toString()); //get the field and convert into string } } catch(Exception e) { System.out.println(e.toString()); //print the exceptio object e } } public ClassgetDeclaredFieldsExample1() { // Default Constructor } public ClassgetDeclaredFieldsExample1(long l, int i , String p) { //parameterized constructor with 3 parameter this.l = l; this.i = i; this.p = p; } long l = 66788; int i = 8; String p = "javaTpoint"; }
Output