Static keywords in Java

Source: Internet
Author: User

In Java, you can use static to declare attributes and methods. This attribute or method is also called a class method after declaring attributes or methods of the static type. It can be called directly by class names.

Static indicates global or static values. It is used to modify member variables or member methods. It can also form static code blocks.

The static modified member variables and member methods are independent of any objects in the class. That is, they are shared by all instances of the class without relying on specific instances of the class.

As long as the class is loaded, the Java Virtual Machine can find them in the Method Area of the runtime data Zone according to the class name. Therefore, a static object can be accessed before any of its objects are created,

You do not need to reference any objects.

 

What does static and final represent?

Static final is used to modify member variables and member methods. It can be simply understood as a "global constant"

For a variable, it means that once the value is given, it cannot be modified and can be accessed through the class name.

For methods, it means they cannot be overwritten and can be accessed directly by class names.

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.