What is the purpose of toString() method? Or What does the toString() method do in java?

Java 8Object Oriented ProgrammingProgramming

The toString() method returns the current object in String format.

Example

Live Demo

public class Test {
public static void main(String args[]) {
Test obj = new Test();
System.out.println(obj.toString());
System.out.println("Hello");
}
}

Output

Test@2a139a55
Hello
raja
Published on 10-Jan-2018 10:11:43
Advertisements