Object Class


Class java.lang.Object is the root of the class hierarchy. Every class has Object as a superclass. The Object class is beneficial if you want to refer to any object whose type you do not know yet. For example, there is a getObject() method that returns an object, but it can be of any type like Employee, Student, etc. We can then use the Object class to refer to that object. The Object class provides some common behaviors to all the objects; e.g., object can be compared, object can be cloned, object can be notified, etc.

MyObject.java (Object class)
public class MyObject {
  public static void main( String[ ] args ) {
    String  a = "10";
    Object  b = new Integer( 10 );
    if ( b.toString( ).equals( a ) )
      System.out.println( true );
    else
      System.out.println( false );
  }
}
Output:           Result:




      How does Moses make his coffee?    
      Hebrews it.