Essays in ⑨java Variables---class variables (static variables), final variables, member variables, local variables

Source: Internet
Author: User

Variables in Java---class variables (static variables), final variables, member variables, local variables

A ① class variable (also called a static variable) is a variable that is independent of the method in a class, and static modifiers are loaded with the load of the class .

final variable : decorated with the final keyword and cannot be modified. Used with static to represent constants.

member Variable (also called "Instance variable", "Domain"): is also a variable independent of the method in the class, but there is no static adornment. It can be initialized without initialization , and if the reference type is initialized to null by default, the base type, such as int, is initialized to 0 by default.

local variable is a variable in a method of a class. Must be instantiated, otherwise different by compiling. Local variables are allocated in the stack , the volume is large, the life cycle is short, if the virtual machine to each local variable is initialized, is a very large cost, but the variable is not initialized to the default value is not safe to use. Due to the two aspects of speed and security, the solution is to not initialize the virtual machine, but it is required that the writer must assign a value to the variable before using it.

 1  public  class       variable{ 2  static  int  allclicks=0; //  class variable  3  String str= "Hello World"; //  instance variable  4  public   void   method () { 5  int  i = 0; //  local variable  6  }  7  }

Essays in ⑨java Variables---class variables (static variables), final variables, member variables, local variables

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.