Java basics-Object-oriented (objects parent class)

Source: Internet
Author: User

Statement: The material used in this column is written by the VIP students of the Kay Academy, who has the right to be anonymous and has the final right to interpret the article; The Edith Academy is designed to promote students to learn from each other on the basis of public notes.

Object Parent class:

Method of object:
Clone () Object clone
to string () string
Equals (object) Boolean to compare objects for equality
The Get Class () class template object, which obtains the template object through this method.
Hashcode () int converted to digital
GC Garbage Collection

The Equals method explains:
GetClass () Current Object Calss
O.getclass () pass in the object's class
GetClass ()!=o.getclass () The current class is compared to the class passed in, and if the same class is the same, it is not the same class, return false.

Why put o = = NULL in front of the comparison?
Object variables do not point to a piece of memory is not accessible to the inside data, there is no way to access.
If O is empty then an error occurs because O does not get memory is not able to participate in the access.
Null pointer Error!
The Onull will be GetClass ()!=0.getclass () before it is placed in the back, and an error will occur if the O pass in is empty (null).
Onull put it in front, | | is calculated if the preceding is true and will not run after it.

Clone () Cloning: We pass the object, or assign the object is a reference to pass, there is no copy delivery.
Do I want to create a copy of my object? What does object replication typically replicate?
The property value is copied between the object and the Object!
1. Deep cloning: reference to the outside world of the object at the same time to their own.
2. Shallow cloning: The object quoted by the outside world also quoted a copy.

Shallow clone:

Test:
Cloning exception handling: Select the error code area, ALT + ENTER.

Shallow Clone Memory Request:

Deep Clone: A property is stored inside a dog.

Test:

Deep Clone Memory Request:

to string () strings: For printing property values, adding to the string or printing an object automatically calls the to string () method.
Describes the case of the class, the parameter value, and returns a string.
The function of a string return is to introduce the properties of the class, the contents of the class.

Printing method: Introduce, print out the attribute value.

GC Garbage Collection: The System.GC () method facilitates garbage collection startup.
What objects will be recycled?
Dog Dog=new Dog ();
Dog=null; As long as your object does not have an object variable pointing, Java can automatically reclaim your object. Memory that is not referenced by any variable is recycled.
In older versions of the JDK, you would call Finalize () for notification as soon as you recycle the object.

Java basics-Object-oriented (objects parent 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.