Sobes.tech
Junior — Middle

Is it mandatory to specify inheritance from the base class Object in your classes in the programming language?

sobes.tech AI

Answer from AI

In Java, all classes implicitly inherit from the base class Object, even if inheritance is not explicitly specified. Therefore, specifying extends Object in the class declaration is not necessary and is usually omitted.

For example, these two classes are equivalent:

public class MyClass {
    // class body
}

public class MyClass extends Object {
    // class body
}

The compiler automatically adds inheritance from Object if no other inheritance is specified.