Java----references to objects and objects

Source: Internet
Author: User

The references to objects and objects in Java are two confusing notions of what kind of relationship a reference to an object and an object are.

First, the object

Learn the object-oriented language of the students can understand what the concept of the object, in Java all objects, in the code of the world, the object is a specific instance of class, such as a dog called Black is a specific instance of the dog, that is, a dog class object. A class is an abstract concept, and an object is a concrete instance of a class.

Ii. references to Objects

The application must be related to the object, and the question is what kind of management they have. In Java everything is an object, so when we write code, the operation is basically the object, right, then the problem? How do we manipulate the object?

Person person= Thenew person (" Zhang San ");  // create an object and instantiate it Person                 Person2;                     // Create a reference        to an object person2=New person (" John Doe ");        // create an object and let the persons reference point to that object

This is how I create objects in the program, right we create an object by invoking the constructor of the class, which is the new person ("Zhang San") and the new person ("John Doe") in the code above, and these two words create an object.

So it is true that we created the object in memory, but how do we manipulate the two objects, such as: We want to set Zhang San age to 22 years old:

// set the age        of Zhang San Person.setage (a);

Yes, we're using person, and it's obvious that this person is a reference to the object that we're manipulating "Zhang San", so it's easy to see what the reference is, and what the object and object references are related to. In "Think in Java"

It concludes that the reference to the object is a remote control of the object we are manipulating.

Java----references to objects and objects

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.