Q:

Java program to get the list of fields of a class

belongs to collection: Java Class and Object Programs

0

Java program to get the list of fields of a class

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program/Source Code:

The source code to get the list of fields of a class is given below. The given program is compiled and executed successfully.

// Java program to get the list of fields 
// of a class

import java.lang.reflect.Field;
public class Main {
  public static void main(String[] args) throws ClassNotFoundException {
    Class cls = Class.forName("java.lang.Double");

    Field fields[] = cls.getFields();

    System.out.println("Fields of Double class: ");
    for (Field field: fields)
      System.out.println(field);
  }
}

Output:

Fields of Double class: 
public static final double java.lang.Double.POSITIVE_INFINITY
public static final double java.lang.Double.NEGATIVE_INFINITY
public static final double java.lang.Double.NaN
public static final double java.lang.Double.MAX_VALUE
public static final double java.lang.Double.MIN_NORMAL
public static final double java.lang.Double.MIN_VALUE
public static final int java.lang.Double.MAX_EXPONENT
public static final int java.lang.Double.MIN_EXPONENT
public static final int java.lang.Double.SIZE
public static final int java.lang.Double.BYTES
public static final java.lang.Class java.lang.Double.TYPE

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java Class and Object Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Java program to get the list of defined classes an... >>
<< Java program to get the package name of a class...