There is a special class in Java: Object

Source: Internet
Author: User

There is a special class in Java: Object. It is the parent class of all classes in the Java system (either the immediate parent class or the indirect parent class).

The methods in this class can inherit all of the classes.

The three methods described below belong to object:

(1) Finalize method: A method that is called when an object is garbage collected.

(2) toString (): The object is represented by a string.

When we print the defined object directly, it is implied that the return value of the print ToString () is printed.

The parent class's ToString () can be overridden by a subclass as a ToString ().

To get the form we want, that is, we should overwrite ToString () when we wish to describe the object in a custom way.

(3) Equal

First try to compare the following example:

String A=new string ("Hello");

String A=new string ("Hello");

A==b (This time the program returns false)

Because the address is stored in AB at this point, because a new object is created, a different address is stored.

1  PackageTomtext;2 //This example combines the basic data types to illustrate how to use variables. 3  Public classtomtext_35 {4      Public Static voidMain (String args[]) {5         byteb = 0x55;6          Shorts = 0x55ff;7         inti = 1000000;8         LongL = 0xfffL;9         Charc = ' C ';Ten         floatf = 0.23F; One         DoubleD = 0.7E-3; A         BooleanBOOL =true; -System.out.println ("b=" +b); -System.out.println ("s=" +s); theSystem.out.println ("i=" +i); -System.out.println ("l=" +l); -System.out.println ("c=" +c); -System.out.println ("f=" +f); +System.out.println ("d=" +d); -System.out.println ("bool=" +bool); +         }     A  at}

There is a special class in Java: Object

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.