Java-Object Class

Object Class

The Object class is a superclass of all other classes. This means all other classes are subclass of the Object class. The important methods in the Object class are briefly described in the following table. These methods are inherited by every object created in a Java program.

Method Purpose
Object clone() Creates a new object that is the same as the object being cloned.
boolean equals(Object obj) Determines whether one object is equal to another.
void finalize() Called before an unused object is recycled.
Class getClass() Obtains the class of an object at run time.
int hashCode() Returns the hash code associated with the invoking object.
void notify() Resumes execution of a thread waiting on the invoking object.
void notifyAll() Resumes execution of all threads waiting on the invoking object.
String toString() Returns a string that describes the object.
void wait() Waits on another thread of execution.

Program

000000

Program

class Data {
    
    int data1;
}

class Javaapp {
    
   public static void main(String args[]) {
       
       Data d1 = new Data();
       System.out.println(d1.toString());
       System.out.println(d1.hashCode());
   }
}

Leave a Comment