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


To access the url field we can use the following

socket.url = "";

We can get the value of the field,

String apiUrl = socket.url;

Accessing Object Methods

The general form of accessing methods is as follows


We can call the connect method from the Socket class as follows :


We can call the send method which takes one argument as follows :


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!");

results matching ""

    No results matching ""