[Share] about static, final, final static

Source: Internet
Author: User

I can see that someone is discussing static and final. I also want to sum up, hey.

Static Method

Generally, a method is defined as static in a class, that is, this method can be called without the objects of this class.
To call a static method is "class name. Method Name". The use of static methods is simple.
Generally, static methods are usually used for applications.ProgramOther classes in Java provide some practical tools for this purpose.

Static variable

Static variables are similar to static variables. All such instances share this static variable, that is, when the class is loaded,Allocate only one bucketAll such objects can manipulate the block storage space.

Final member

When you define a variable in a class and add the final keyword before it, this variable cannot be changed once initialized, the unchangeable meaning here is that its value is immutable for the basic type, and its reference for the object variable cannot be changed. It can be initialized in two places. One is its definition, that is, it is assigned a value directly when the final variable is defined, and the other is in the constructor. You can only choose one of these two places.

Static finalYou do not need to declare the class object to use, but can not be changed. The whole constant. (Class constant)

And static final and final static seems to have no difference, do not know, who knows tell me, MSN: caoxicao@hotmail.com

 

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.