•In java, “Object” is a class which is available in java.lang package.
•In java, “Object” is the implicit superclass of every other class including the user defined classes.
•So, object of every class will be able to use the methods in the class “Object”.
Methods in Object class:
•clone() – Used to create an exact clone of the existing object.
Syntax:
Object clone()
•equals() – Used to check whether two object references are equal or not.
Syntax:
boolean equals(Object object)
•finalize() – Invoked when an unused object is being garbage collected from memory.
Syntax:
protected void finalize()
•getClass() – Used to get the class of the object at runtime.
Syntax:
Class getClass()
•hashCode() – Returns the hash code associated with the object.
Syntax:
int hashCode()
•toString() – Returns the string representation of an object.
Syntax:
String toString()
•wait() – Waits on another thread of execution.
Syntax:
void wait()
•notify() – Used to resume the execution of a thread waiting on the invoking object.
Syntax:
void notify()
•notifyAll() – Used to resume the execution of all threads waiting on the invoking object.
Syntax:
void notifyAll()
•The following methods in the Object class are declared as “final”. Means these methods cannot be overriden.
1) getClass()
2) wait()
3) notify()
4) notifyAll()
Summary of methods in Object:
•In java, “Object” is the implicit superclass of every other class including the user defined classes.
•So, object of every class will be able to use the methods in the class “Object”.
Methods in Object class:
•clone() – Used to create an exact clone of the existing object.
Syntax:
Object clone()
•equals() – Used to check whether two object references are equal or not.
Syntax:
boolean equals(Object object)
•finalize() – Invoked when an unused object is being garbage collected from memory.
Syntax:
protected void finalize()
•getClass() – Used to get the class of the object at runtime.
Syntax:
Class getClass()
•hashCode() – Returns the hash code associated with the object.
Syntax:
int hashCode()
•toString() – Returns the string representation of an object.
Syntax:
String toString()
•wait() – Waits on another thread of execution.
Syntax:
void wait()
•notify() – Used to resume the execution of a thread waiting on the invoking object.
Syntax:
void notify()
•notifyAll() – Used to resume the execution of all threads waiting on the invoking object.
Syntax:
void notifyAll()
•The following methods in the Object class are declared as “final”. Means these methods cannot be overriden.
1) getClass()
2) wait()
3) notify()
4) notifyAll()
Summary of methods in Object:
No comments:
Post a Comment