Sobes.tech
Junior — Middle

Which classes in Java are descendants of the Object class?

sobes.tech AI

Answer from AI

In Java, all classes except primitive types implicitly inherit from the java.lang.Object class. This means that any user-defined class, as well as all built-in Java classes, are descendants of Object. For example, if you create a class class MyClass {}, it automatically inherits methods from Object, such as toString(), equals(), hashCode(), getClass(), and others.

Therefore, all classes in Java, except primitive types (int, boolean, etc.), are descendants of Object.

Example:

class MyClass {
    // this class inherits from Object automatically
}

MyClass obj = new MyClass();
System.out.println(obj.toString()); // method from Object
Which classes in Java are descendants of the Object… - sobes.tech