The Object Class

This lesson discusses the root class of all objects in Java.

We'll cover the following...

Question # 1

What is the Object class?

The Object class is the superclass directly or indirectly of every other class in Java. The Object class itself doesn't have any superclass. In the absence of any other explicit superclass, every class is implicitly a subclass of Object.

Implicit Object Superclass

// Class is implicity a derived class
// of the Object class
public class ObjectSubclass {

}

(new ObjectSubclass()) instanceof Object // Prints true
Press + to interact
class HelloWorld {
public static void main( String args[] ) {
System.out.println((new ObjectSubclass()) instanceof Object);
}
}
class ObjectSubclass {
}

Question # 2

What are the methods defined in the Object class?

The methods defined in the Object class include:

  • clone()
  • equals()
  • hashCode()
  • finalize()
  • getClass()
  • toString()

Question # 3

What is the output of the below snippet?

    String obj1 = new String("abc");
    String obj2 = new String("abc");
    System.out.println(obj1 == obj2);
1
A)

false

B)

true

Question 1 of 40 attempted

The equals() method provided in the Object class uses the identity operator == to determine whether two ...