Differences between instance variables and class variables

Source: Internet
Author: User

I flipped through the new Java entry book last night and suddenly saw three variables in Java:
1. Local variable 2. instance variable 3. Class variable
Local variables are easy to understand. The scope and life cycle are the same as those in the Delphi function, but the two or three variables are somewhat confusing. I checked the information online and found the answer.
An instance variable means that when a class has multiple instances, there are as many instances as the variable, that is, an instance has the operation permission of an instance variable, you cannot change the instance variables of other instances.
In fact, class variables are somewhat like "global variables" in Delphi, and are "engineering-level" global variables. Referencing in Delphi is like a unit to operate on another unit variable, similar meaning. In Java, multiple class instances use one variable together. The variable that can be operated by multiple class instances is a class variable in Java.

Local variables exist in the stack, and the computing speed is very fast, while the calculation speed of instance variables and class variables is very slow. They are stored in a constant storage zone, JVM requires specialized maintenance and optimization, which is included in csdn.ArticleThe address of how to improve the efficiency of variable usage is:
Http://dev.csdn.net/article/34/34382.shtm
For more information, see.
Learning a new language is to start from scratch ~~~~~~~

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.