Common parent class for all classes: Object class
Method 1:tostring ()
Method 2:equals () compares the reference of an object to a memory address
You can compare the class type of an object with the same property value by overriding the Equals () method: Right-click, source-, overriding Equals and Hashcode methods
GetClass () Method: Returns the class type of the class
Class type: Focus on the property name of the class
Type of class: Focus on the property value of the class
1 Public classEquals {2 3 Public Static voidMain (string[] args) {4 //TODO auto-generated Method Stub5String A1 =NewString ("123ads");6String A2 =NewString ("123ads");7 if(a1==A2)8 {9System.out.println ("= =");Ten } One if(A1.equals (A2)) A { -System.out.println ("String equals"); - } theCar car1 =NewCar (); -Car car2 =NewCar (); - if(car1==car2) - { +System.out.println ("= ="); - } + if(Car1.equals (CAR2)) A { atSystem.out.println ("Equals"); - } - } - -}
View Code
Java second day classes and objects