VOOZH about

URL: https://www.geeksforgeeks.org/java/class-tostring-method-in-java-with-examples/

⇱ Class toString() method in Java with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Class toString() method in Java with Examples

Last Updated : 12 Jul, 2025
The toString() method of java.lang.Class class is used to convert the instance of this Class to a string representation. This method returns the formed string representation. Syntax:
public String toString()
Parameter: This method does not accept any parameter. Return Value: This method returns the String representation of this object. Below programs demonstrate the toString() method. Example 1:
Output:
Class represented by c1: class java.lang.String
Example 2:
Output:
Class represented by c2: int
Class represented by c3: void
Reference: https://docs.oracle.com/javase/9/docs/api/java/lang/Class.html#toString--
Comment