Java final. Static modifier

Source: Internet
Author: User
  • Static modifiers (member variables, constants, and member methods decorated with the static modifier become static variables, constants, and methods, they are collectively called static members, are owned by the entire class, are not dependent on a particular instance of the class, are shared by all instances of the class, and, as long as the class is loaded, The JVM can find them in the method area of the run-time data area based on the class name)
  1. static variables

For static variables, at run time, the JVM allocates only one memory for static variables at a time, and completes the memory allocation of static variables during class loading. Inside a class, static variables can be accessed directly within any method, and in other classes, static variables in the class can be accessed through the class name.

Static variables can be shared by all instances of a class, so static variables can be used as shared data between instances, increasing the interactivity between instances.

If all instances in a class have an identical constant property, you can define this property as a static variable. For example:

Static Double pi=3.1415;

2. Static methods

A static method does not need to be called by any instance of the class it belongs to, so the This keyword cannot be used in a static method, nor can it directly access the instance variables and instance methods of the owning class, but the static and static methods of the owning class are directly accessible, and, as with this, Super is also related to a particular instance of a class, so it cannot be used in static methods.

    

Java final. Static modifier

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.