Thursday, October 2, 2025
HomeLanguagesJavaConstructor getName() method in Java with Examples

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 declaring class.

Syntax:

public String getName()

Parameters: This method accepts nothing.

Return: This method returns the simple name of the underlying member in String format.

Below programs illustrate getName() method:
Program 1:




// Java program to illustrate getName() method
  
import java.lang.reflect.Constructor;
  
public class GFG {
  
    public static void main(String[] args)
    {
        // create a class object
        Class classObj = String.class;
  
        // get Constructor object array
        // from class object
        Constructor[] con
            s
            = classObj.getConstructors();
  
        // apply getName method
        System.out.println("Constructor : "
                           + cons[0].getName());
    }
}


Output:

Constructor : java.lang.String

Program 2:




// Java program to illustrate getName() method
  
import java.lang.reflect.Constructor;
import java.util.ArrayList;
  
public class GFG {
  
    public static void main(String[] args)
    {
        // get Constructor object for class object
        Constructor constructor
            = ArrayList.class.getConstructors()[0];
  
        // apply getName method
        String name = constructor.getName();
  
        // print result
        System.out.println("Constructor Name : "
                           + name);
    }
}


Output:

Constructor Name : java.util.ArrayList

References: https://docs.oracle.com/javase/10/docs/api/java/lang/reflect/Constructor.html#getName(java.lang.Object)

RELATED ARTICLES

Most Popular

Dominic
32330 POSTS0 COMMENTS
Milvus
85 POSTS0 COMMENTS
Nango Kala
6703 POSTS0 COMMENTS
Nicole Veronica
11867 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11926 POSTS0 COMMENTS
Shaida Kate Naidoo
6817 POSTS0 COMMENTS
Ted Musemwa
7078 POSTS0 COMMENTS
Thapelo Manthata
6775 POSTS0 COMMENTS
Umr Jansen
6774 POSTS0 COMMENTS