Object is the root class of Java's class hierarchy.

Every class in Java directly or indirectly extends Object.

class Student {
}

is conceptually:

class Student extends Object {
}

So every Java object gets methods provided by Object.

The three most important ones are:


1. toString()

toString() returns a string representation of an object.

class Student {
    String name = "Rahul";
}
Student s = new Student();

System.out.println(s.toString());

If you don't override it, the default implementation generally produces a string containing the class name and object's identity-related hash representation.

You can override it to provide meaningful information:

@Override
public String toString() {
    return "Student{name='" + name + "'}";
}

Now:

System.out.println(s);