Home » Java programming language

Java Class class getName() method with example

Class class getName() method: Here, we are going to learn about the getName() method of Class class with its syntax and example.
Submitted by Preeti Jain, on November 21, 2019

Class class getName() method

  • getName() method is available in java.lang package.
  • getName() method is used to return the name of the classes, an interface, a primitive type, a void type, an array class denoted by this Class object.
  • getName() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
  • getName() method does not throw an exception at the time of returning the name of classes or an interface.


    public String getName();


  • It does not accept any parameter.

Return value:

The return type of this method is String, it returns the name of the class or an interface.


// Java program to demonstrate the example 
// of String getName() method of Class 

public class GetNameOfClass {
    public static void main(String[] args) {
        Thread th = new Thread();

        // Get Class object of Thread
        Class cl = th.getClass();

        // It return the name of the class Thread
        String class_name = cl.getName();

        // Display Class Name
        System.out.println("Class Name :: " + class_name);


Class Name :: java.lang.Thread

Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.