StackTraceElement.getClassName() Method

Advertisements


Description

The java.lang.StackTraceElement.getClassName() method returns the fully qualified name of the class containing the execution point represented by this stack trace element.

Declaration

Following is the declaration for java.lang.StackTraceElement.getClassName() method

public String getClassName()

Parameters

  • NA

Return Value

This method returns the fully qualified name of the Class containing the execution point represented by this stack trace element.

Exception

  • NA

Example

The following example shows the usage of java.lang.StackTraceElement.getClassName() method.

package com.tutorialspoint;

import java.lang.*;

public class StackTraceElementDemo {

   public static void main(String[] args) {

      function1();
   }
 
   public static void function1()
   {
      new StackTraceElementDemo().function2();
   }
 
   public void function2() 
   {
      System.out.print("class name : ");
      System.out.print(Thread.currentThread().getStackTrace()[1].
      getClassName());
   }
}

Let us compile and run the above program, this will produce the following result:

class name : StackTraceElementDemo



Advertisements
Advertisements