Reputation: 43
When I try compiling this code I get various errors; the one which I'm most suspicious of is:
constructor Socket in class Socket cannot be applied to given types
Here is my code:
import java.io.*;
import java.net.*;
public class Socket {
public static void main(String[] args) {
try {
Socket s = new Socket("localhost", 6666);
DataOutputStream dout = new DataOutputStream(s.getOutputStream());
dout.writeUTF("Hello Server");
dout.flush();
dout.close();
s.close();
} catch (Exception e) {
System.out.println(e);
}
}
}
Upvotes: 1
Views: 104
Reputation: 106450
Since you've called your own class Socket
, you'll need to use the fully qualified name to refer to Java's Socket
class.
java.net.Socket s = new java.net.Socket("localhost",6666);
In the future, I would advise against naming your class something similar to what's in the existing API to avoid confusion like this.
Upvotes: 3