Global variables and local variables in Java

Source: Internet
Author: User

Global variable: Also called a member variable, refers to a variable defined in a class; it works in the entire class.

Global variables can also be divided into: class variables and instance variables

1. Class variables: Also known as static variables are modified with static it can be called directly with the class name can also be called with the object and all objects of the same class variable is shared with the same block of memory space

2. Instance variable: Without static decoration It can only be called through an object and the same instance variable of all objects is shared with different memory spaces

Local variables: Refers to the variables that are defined in the method body and the parameters of the method that are valid only within the method that defines it

Note: If the name of a local variable in a method is the same as the name of a global variable, the global variable is temporarily invalidated in this method

Global variables and local variables in Java

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.