Java final static and final differences

Source: Internet
Author: User

The difference between static and non-static is only revealed if the value is initialized during runtime. Because the values during compilation are considered by the compiler to be phase

The same.

 Packagethinking; Public classFinalData {//Can be Compile-time constants    Final intI1 = 9; Static Final intI2 = 99; //Typical public constant:     Public Static Final intI3 = 39; //cannot be Compile-time constants:    Final intI4 = (int) (Math.random () *20); Static Final inti5 = (int) (Math.random () *20);  Public voidprint (String id) {System.out.println (id+ ":" + "I4 =" + I4 + ", i5 =" +i5); }             Public Static voidMain (string[] args) {FinalData fd1=NewFinalData (); FinalData FD2=NewFinalData (); Fd1.print ("Fd1"); Fd2.print ("Fd2"); }}

Note that for FD1 and FD2, the value of I4 is unique, but the value of i5 does not change due to the creation of another FinalData object

Change. That is because its properties are static and initialized at load time, rather than when each object is created.

Java final static and final differences

Related Article

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.