Static final constant

Source: Internet
Author: User

Package oo.day06;
Static final constant
public class Staticfinaldemo {
public static void Main (string[] args) {
Aoo.num = 250; Compilation errors, constants cannot be modified
System.out.println (Aoo.num);

1. Loading Boo.class in the method area
2. Storing NUM1 in the method area
3. Go to the method area to get the value of the NUM1 and output
System.out.println (BOO.NUM1);

The compiler is directly replaced with a specific value at compile time, high efficiency
Equivalent to SYSTEM.OUT.PRINTLN (6);
System.out.println (BOO.NUM2);
}
}
Class boo{
public static int NUM1 = 5; static variables
public static final int NUM2 = 6; Constant
}


Class aoo{
public static final int NUM = 5; Constant
public static final double PI; Compile error, must declare simultaneous initialization
}

Static final constant

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.