There are a number of method types in the object class, which are learned in several lessons:
Public Booleanequals (Object o);//returns whether the calling object (this) is the same as the O object//return o = = this//Typically, you want to overwrite, determine whether two objects are the same type, and whether the encapsulated values are the same Public classstudent{PrivateString sname; Private intAge ; PrivateString Sno; Public Booleanequals (Object o) {if(NULL= = O)return false; if(O.getclass () = = This. GetClass ()) {Student s=(Student) o; return This. Sname.equals (S.sname) && This. Age = = S.age && This. Sno.equals (S.sno) }}}
Protected Object Clone () throws Clonenotsupportedexception
Protected Object Clone ()throwsclonenotsupportedexception//return a clone of this instrance//throws Clonenotsupportedexception, if this class does not write implements Cloneable, this exception will be thrown//This copy is a shallow copy, copying only the property values of the object, and for the reference property, simply copying the reference//Example Public classStudentImplementscloneable{ PublicString name; Public intAge ; Public Static voidMain (string[] args) {Student s=NewStudent (); S.name= "Zhangsan"; S.age= 18; Try{Student s2=(Student) S.clone (); System.out.println (S.name); System.out.println (S2.name); }Catch(Clonenotsupportedexception r) {}}}
Public String toString ()
Public String toString () // returns:a string representation of the object. // The default is GetClass (). GetName () + ' @ ' + integer.tohexstring (hashcode ())
protected void Finalize () throws Throwable
protected void Finalize () throws throwable // called before the virtual machine cleans up the garbage object
Split Line---------------------------------------------------------------------------------------------------------------
Java Object class