What does dot(.) represent in a Java statement

Using Dot (.) operator with an Object, you can access its methods and properties. In general, with a Dot Operator, you can access the members of a package or class.

For Example:

class Student{
    private int roll;

    public void setRoll(int r)
    {
        this.roll=r;
    }

    public int getRoll(){
        return this.roll;
    }
}


class UseStudent{
    public static void main(String []args)
    {
        Student s=new Student();
        s.setRoll(101); //Accessing roll method of Student using Dot operator
        System.out.println(s.getRoll()); 
    }
}

Leave a Comment