Field getType() method in Java with Examples Last Updated : 26 Aug, 2019 Comments Improve Suggest changes Like Article Like Report The getType() method of java.lang.reflect.Field used to get the declared type of the field represented by this Field object.This method returns a Class object that identifies the declared type Syntax: public String getType() Parameters: This method accepts nothing. Return value: This method returns a Class object that identifies the declared type. Below programs illustrate getType() method: Program 1: Java // Java program to demonstrate getType() method import java.lang.reflect.Field; public class GFG { public static void main(String[] args) throws Exception { // Get the marks field object Field field = User.class.getField("Marks"); // Apply getType Method on User Object // to get the Type of Marks field Class value = field.getType(); // print result System.out.println("Type" + " is " + value); // Now Get the Fees field object field = User.class.getField("Fees"); // Apply getType Method on User Object // to get the Type of Fees field value = field.getType(); // print result System.out.println("Type" + " is " + value); } } // sample User class class User { // static double values public static double Marks = 34.13; public static float Fees = 3413.99f; public static double getMarks() { return Marks; } public static void setMarks(double marks) { Marks = marks; } public static float getFees() { return Fees; } public static void setFees(float fees) { Fees = fees; } } Output: Type is double Type is float Program 2: Java // Java program to demonstrate getType() method import java.lang.reflect.Field; import java.time.Month; public class GFG { public static void main(String[] args) throws Exception { // Get all field objects of Month class Field[] fields = Month.class.getFields(); for (int i = 0; i < fields.length; i++) { // print name of Fields System.out.println("Name of Field: " + fields[i].getType()); } } } Output: Name of Field: class java.time.Month Name of Field: class java.time.Month Name of Field: class java.time.Month Name of Field: class java.time.Month Name of Field: class java.time.Month Name of Field: class java.time.Month Name of Field: class java.time.Month Name of Field: class java.time.Month Name of Field: class java.time.Month Name of Field: class java.time.Month Name of Field: class java.time.Month Name of Field: class java.time.Month References: https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Field.html#getType-- Create Quiz Comment A AmanSingh2210 Follow 0 Improve A AmanSingh2210 Follow 0 Improve Article Tags : Java Java-Functions java-lang-reflect-package Java-Field Explore Java BasicsIntroduction to Java3 min readJava Programming Basics9 min readJava Methods6 min readAccess Modifiers in Java4 min readArrays in Java7 min readJava Strings7 min readRegular Expressions in Java3 min readOOP & InterfacesClasses and Objects in Java5 min readAccess Modifiers in Java4 min readJava Constructors4 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages2 min readJava Interface7 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java4 min readIterator in Java4 min readJava Comparator Interface5 min readException HandlingJava Exception Handling6 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java7 min readFile Handling in Java4 min readJava Method References9 min readJava 8 Stream Tutorial7 min readJava Networking6 min readJDBC Tutorial5 min readJava Memory Management4 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers15+ min readJava Programs - Java Programming Examples7 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz1 min readJava Project Ideas For Beginners and Advanced15+ min read Like