A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Java program to get the list of fields of a class
Q:

Java program to get the list of fields of a class

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)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now