Java-Preliminary Understanding-seventh chapter-this key characters

Source: Internet
Author: User
Tags modifier

One.

After the data has been modified by static, what good is it? (The birth of a new thing, always has its advantages)

Country data is shared by all objects, does country exist first, or does the object exist first? Country is present before it can be shared by all objects.

Country data exists before the object appears, then country can be used, no object, to whom?

Country is defined in the class, then the analogy country must exist first. The order is this, preceded by a class, then country, and finally the object.

Data that is statically decorated can be used not only by the object, but also by a calling method that can be called by the class name.

→ since statically decorated data appears before the object, the static data is not just called by the object, it can be called by the class name, and the class appears before the static data .

The static modified member variable country can be accessed by the class name. Look at the following, the output statement is written in Person.country, not p.country. Of course, object invocation is also possible.

The person in the person.country here refers to the name of the class, no other meaning? Describes a class that invokes its own member variable that can be completely said in the past.

The role of static: More than one way to call. You can call a member directly without creating an object.

This gives a problem that the class name can call the member variable directly, so what is the use of object invocation? Imagine that if the name of the object is also decorated with the static modifier, then multiple objects share a name data, if an object named "Xiao Qiang", then everyone is called "Xiao Qiang" ( an object is assigned to "Xiao Qiang", everyone is called "Xiao Qiang", How to do? To make this happen? )。

Some data is shared, but some data is unique and needs to be encapsulated internally by the object,

Static modifies the data to form a share to save heap memory space.

For example, the shared data is likened to a water dispenser, and each cup is likened to an object's unique data. Enhance understanding of the principles of boring computers through specific examples of life. The computer language is the analytic reconstruction to the real life, so each knowledge point, behind all corresponds to the life example. And the object has not existed, the water dispenser has been, the cup is with the appearance of the object, and the water dispenser is with the emergence of the classroom.

Is the modifier meant to represent access rights?

let's look at features 3 and 4. 3 says the static priority object exists, then the description class is loaded into the stack before the object is created? Is it fixed loading every time? 4 static members are called directly by the class name, that is, the main function in the execution of this sentence, is to load the description class?

Class name invocation is a very good way to simplify (no need to first create an object and then call it through an object).

We manipulate the object to call members more times, the object is more characteristic, if all use the class name to call, then the description is shared data, but also need so many objects to do.

→ Here is the classification of the data, shared and unique.

Java-Preliminary Understanding-seventh chapter-this key characters

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.