Variables in Java

Source: Internet
Author: User
1. Local variables: Refers to the variables defined in the method body and the parameters of the method, it is only in the method of defining its valid, as the operation of the class temporarily stored data. 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. 2.final variable (instance field): Declares the member variable as final as the instance field. The final member variable must be initialized at the time of declaration or initialized in the constructor, or a compilation error occurs. And in a later operation, it can no longer be modified. 3. Static variables: If you define a variable as static, there is only one such domain in each class (the same class variable for all objects is shared with the same block of memory space). Each object has its own copy of all instance fields. A static domain belongs to a class and does not belong to any independent object. 4. Static constants: Using the static final decoration. 5. Global variables: Also called member variables. Both the static domain and the instance domain are global variables. is relative to a local variable: it can be used in multiple functions of the entire class. 6. Static method: A static method is a method that cannot be applied to an object. The static method cannot access the instance domain because it cannot manipulate the object. However, static methods can access the static domain of the class in which they reside.  There are two situations where static methods are used: (1) A method does not require access to the object state, and the required parameters are provided through explicit arguments. (2) A method only needs to access the static domain of the class.

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.