Using Objects
Once objects are created we can access thier members using the dot operator, (.).
Accessing Field Object Members
The general form of accessing fields is
objectReference.fieldName
To access the url
field we can use the following
socket.url = "http://chat.peruzal.co.za";
We can get the value of the field,
String apiUrl = socket.url;
Accessing Object Methods
The general form of accessing methods is as follows
objectReference.methodName(arguments);
We can call the connect
method from the Socket
class as follows :
socket.connect();
We can call the send method which takes one argument as follows :
socket.send("Howdy!");
We can also pass in multiple parameters separated by commas. For the send
method, declared as follows
public class Socket {
void send(String username, String message){
}
}
We can call the method as follows :
socket.send("joseph", "Java is awesome!");