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