Java second day classes and objects

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.