Method | Purpose |
---|---|
toString() | This method returns a String object that describes the current object. In the inherited version of the method, this will be the name of the class, followed by ‘@’ and the hexadecimal representation for the object. This method is called automatically when you concatenate objects with String variables using +. You can override this method in your classes to return your own String object for your class. |
equals() | This compares the reference to the object passed as an argument with the reference to the current object and returns true if they are equal. Thus true is returned if the current object and the argument are the same object (not just equal—they must be one and the same object). It returns false if they are different objects, even if the objects have identical values for their data members. |
getClass() | This method returns an object of type Class that identifies the class of the current object. |
hashCode() | This method calculates a hashcode value for an object and returns it as type int. Hashcode values are used in classes defined in the package java.util for storing objects in hash tables. |
notify() | This is used to wake up a thread associated with the current object. |
notifyAll() | This is used to wake up all threads associated with the current object. |
wait() | This method causes a thread to wait for a change in the current object. |
The two protected methods that your classes inherit from Object are:
Method | Purpose |
---|---|
clone() | This will create an object that is a copy of the current object regardless of type. This can be of any type, as an Object variable can refer to an objectof any class. Note that this does not work with all class objects and does not always do precisely what you want. |
finalize() | This is the method that is called to clean up when an object is destroyed. |
To show you how can you take advantage of the Object class I created a simple example. Click here to download the code.
No comments:
Post a Comment