I’ve written a class which extends Socket class – with the intention of retaining all the methods from a regular socket, while adding two methods of my own:
public class ClientSocket extends Socket{
private long lastOnline;
public ClientSocket() {
super();
}
public long getLastOnline() {
return lastOnline;
}
public void setLastOnline(long lastOnline) {
this.lastOnline = lastOnline;
}
When I’m trying to initialize a new instance of this class, and to add an open socket to it, I’m doing something wrong (or maybe something is wrong with me ), and it tells me that I cannot set a socket to ClientSocket object (although it extends Socket):
ClientSocket socket = serverSocket.accept();
How can I resolve this? Thanks!
serverSocket.accept()returns an ordinarySocket, not aClientSocket.A
ClientSocketis aSocket, but not vice-versa.