Online Java Compiler By
JavaTpoint.com
//import statements import java.lang.reflect.*; public class ClassgetDeclaredFieldsExample2 { public static void main(String[] args) { try { ClassgetDeclaredFieldsExample2 obj = new ClassgetDeclaredFieldsExample2(23); 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 ClassgetDeclaredFieldsExample2(int i) { // Default Constructor this.i=i; } public ClassgetDeclaredFieldsExample2(long l, int i , String p , float f , boolean b) { //parameterized constructor with 3 parameter this.l = l; this.i = i; this.p = p; this.f = f; this.b = b; } long l = 66788; int i = 8; String p = "javaTpoint"; float f = 9 ; boolean b = true; }
Output