Constructor getDeclaringClass() method in Java with Examples Last Updated : 29 Oct, 2019 Comments Improve Suggest changes Like Article Like Report The constructor class provides information about a single constructor for a class and it also provides access to that constructor. The getDeclaringClass() method of java.lang.reflect.Constructor is used to return the class object representing the class that declares the constructor represented by this object. This method returns the name of the source class of this constructor. Syntax: public Class<T> getDeclaringClass() Parameters: This method accepts nothing. Return: This method returns an object representing the declaring class of the underlying member. Below programs illustrate getDeclaringClass() method: Program 1: Java // Java program to illustrate getDeclaringClass() method import java.lang.reflect.Constructor; public class Main { public static void main(String[] args) { // get Constructor object array // from String class object Constructor[] cons = String.class.getConstructors(); Constructor constructor = cons[0]; // apply getDeclaringClass method Class classObj = constructor.getDeclaringClass(); // print result System.out.println("Source class name : " + classObj.getName()); } } Output: Source class name : java.lang.String Program 2: Java // Java program to illustrate getDeclaringClass() method import java.lang.reflect.Constructor; import java.util.ArrayList; public class Main { public static void main(String[] args) { // get Constructor object for class object Constructor constructor = ArrayList.class.getConstructors()[0]; // apply getDeclaringClass method Class classObj = constructor.getDeclaringClass(); // print result System.out.println( "Class Name : " + classObj.getName()); } } Output: Class Name : java.util.ArrayList References: https://docs.oracle.com/javase/10/docs/api/java/lang/reflect/Constructor.html#getDeclaringClass(java.lang.Object) Comment More infoAdvertise with us Next Article Constructor getDeclaringClass() method in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java Java-Constructors Java-Functions java-lang-reflect-package Practice Tags : Java Similar Reads Class getDeclaringClass() method in Java with Examples The getDeclaringClass() method of java.lang.Class class is used to get the declaring class of this class. The method returns the declaring class of this class, if this class or interface is a member of another class. Else this method returns null. Syntax: public Constructor getDeclaringClass() Param 2 min read Constructor getDeclaredAnnotations() method in Java with Examples The getDeclaredAnnotations() method of java.lang.reflect.Constructor class is used to return annotations present on this Constructor element as an array of Annotation class objects. The getDeclaredAnnotations() method ignores inherited annotations on this constructor object.Returned array can contai 2 min read Constructor getName() method in Java with Examples The constructor class provides information about a single constructor for a class and it also provides access to that constructor. The getName() method of java.lang.reflect.Constructor is used to return this constructor name, as a string. Constructor name is the binary name of the constructor's decl 1 min read Class getEnclosingClass() method in Java with Examples The getEnclosingClass() method of java.lang.Class class is used to get the enclosing class of this class. The method returns the enclosing class of this class, if this class is a local class or anonymous class declared in that class. Else this method returns null.Syntax: public Class getEnclosingCla 2 min read Constructor getAnnotation() method in Java with Examples The getAnnotation() method of a Constructor class is used to get this constructor object annotation for the specified type if such an annotation is present, else null. Specified type is passed as parameter. Syntax: public <T extends Annotation> T getAnnotation(Class<T> annotationClass) P 2 min read Like