Sobes.tech
Junior — Middle

Do all objects in Java automatically inherit the equals method from the Object class, or are there exceptions?

sobes.tech AI

Answer from AI

In Java, all classes implicitly inherit from the Object class unless explicitly specified otherwise (for example, if the class is declared as an enum or interface). Therefore, all objects of classes that inherit from Object have the equals method. Exceptions are primitive types (int, boolean, etc.), which are not objects and do not inherit from Object, as well as interfaces and enumerations (enum), which do not inherit from Object directly, but all their instances are ultimately objects and have access to equals.

In other words, all objects created through class have the equals method from Object. But primitives and interfaces are not objects in the full sense and do not have the equals method directly.