Object Superclass

What is the Object class?

The Object class is the superclass of all the other classes in Java. It’s part of the java.lang package.

If a parent class isn’t specified using the extends keyword, the class will inherit from the Object class. For example:

public class A
{
   // class defintion
}

Here, class A inherits from the Object class by default.

✏️ Note: Here’s the complete official documentation of the Object class.

Methods from the Object class

The following two main methods of Object class are used:

  • The toString() method
  • The equals() method

Subclasses of Object often override the equals() and toString() methods with class-specific implementations.

Overriding the toString() method

Look at the code below.

Get hands-on with 1200+ tech skills courses.