Object class Introduction

Source: Internet
Author: User

(1) object is the root class of a class hierarchy, and all classes are inherited directly or indirectly from the object class.
(2) The construction method of the object class has one, and is a parameterless construct
This is actually an understanding of what we said at the time, the construction of the subclass constructor method by default access to the parent class is a non-parametric construct
(3) The method to be mastered:
A:tostring ()
Returns the string representation of an object, by default the hexadecimal representation of the full path + ' @ ' + hash value of the class.
This representation is actually meaningless, and the generic subclass overrides the method.
How do I rewrite it? The process I have also explained, basically is the request information simple and clear.
But it will eventually be generated automatically.
B:equals ()
Compares whether two objects are the same. By default, the comparison is the same as the address value.
Comparing address values is meaningless, so a generic subclass overrides the method.
Rewrite process, I also explained and analyzed in detail.
But it will eventually be generated automatically.
(4) The method to understand:
A:hashcode () returns the hash value of the object. is not an actual address value, which can be understood as an address value.
B:getclass () returns the byte-code file object of the object, which we will explain in detail in the reflection
C:finalize () for garbage collection, at an indeterminate time
D:clone () can implement cloning of an object, including data replication of member variables, but it differs from two references to the same object.
(5) two issues of attention;
A: A direct output of an object name, in fact, the default call to the ToString () method of the object.
B: Face question
The difference between = = and equals ()?
a:==
Base type: Compare whether the value is the same
Reference type: Compares whether the address value is the same
B:equals ()
Only reference types can be compared. By default, the comparison is the same as the address value.
However, we can rewrite the method according to our own needs.

Introduction to the object class

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.