Java easy to confuse concepts such as variables, member variables, local variables

Source: Internet
Author: User

class variables, member variables, local variables

A class variable (also called a static variable) is a variable in a class that is independent of the method and is decorated with static. (Static represents "global", "static", used to decorate member variables and member methods, or static code blocks (static code blocks are independent of class members, the JVM executes static code blocks when loading classes, and each code block executes only once, sequentially)).

Member variables (also known as "instance variables", "fields") are variables that are independent of the method in the class, but do not have static adornments.

A local variable is a variable in the method of a class.


Look at the following pseudo code description:

public class variable{

static int allclicks=0;//class variable

String str= "Hello World";//instance variable

public void Method () {

int i =0;//local variable

}

}

A member variable is also called a field, an instance variable, and is called a property or field in an entity class or data class. When a member variable can be changed, it is called the state of the object.


Constants: With final adornments, values cannot be modified once given

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.