Online Java Compiler By
JavaTpoint.com
import java.io.IOException; import java.net.*; public class JavaSocketToStringExample3 { public static void main(String[] args) throws IOException { //calling the constructor of the socket class Socket socket = new Socket(); //The toString() method converts this socket to a String. //It would return an error, as the socket is not connected. socket.toString(); System.out.println(socket); } }
Output