Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Object class Object package java.lang Object clone equals hashCode toString aCopy toThis hash string ! yesOrNo.

Similar presentations


Presentation on theme: "The Object class Object package java.lang Object clone equals hashCode toString aCopy toThis hash string ! yesOrNo."— Presentation transcript:

1 The Object class Object package java.lang Object clone equals hashCode toString aCopy toThis hash string ! yesOrNo

2 java.lang.Object public class Object Class Object is the root of the class hierarchy. Every class has Object as a superclass. All objects, including arrays, implement the methods of this class. The Object class from the JDK documentation 1 Objects are part of the standard class libraries, not part of the language itself (well not really….)

3 The Object class from the JDK documentation 2 protected Object clone() throws CloneNotSupportedException Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class... In practice most developers have supplied a constructor which takes an instance of the class as an argument instead... … and use this instead of clone() public Object( Object toCopy)

4 The Object class from the JDK documentation 3 public boolean equals( Object toThis) Indicates whether some other object is "equal to" this one... Two instances are equal if they have the same state … even if they are not the same object! Remember object identity & object equality!

5 The Object class from the JDK documentation 4 public int hashCode() Returns a hash code value for the object. This method is supported for the benefit of hashtables such as those provided by java.util.Hashtable This is vital for hashtable collections and they are sufficiently important to require that this method is included in Object. (A hash value is a means of supplying a non-unique key value for key-value pair storage!)

6 The Object class from the JDK documentation 4 public int hashCode() Returns a hash code value for the object. This method is supported for the benefit of hashtables such as those provided by java.util.Hashtable This is vital for hashtable collections and they are sufficiently important to require that this method is included in Object. (A hash value is a means of supplying a non-unique key value for key-value pair storage!)

7 The Object class from the JDK documentation 5 public String toString() Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. Actually it is recommended that all subclasses override all 4 methods specified.


Download ppt "The Object class Object package java.lang Object clone equals hashCode toString aCopy toThis hash string ! yesOrNo."

Similar presentations


Ads by Google