Java Final keyword

Source: Internet
Author: User

finalKeywords do not allow you to modify or replace their original values or definitions. finalkeywords can be used in the following three contexts:

    • Variable declaration

    • class declaration

    • Method declaration

Final variable

If a variable is declared final , it can only be assigned a value once. finalthe value of the variable cannot be modified after it is set. Variable declarations include declarations of local variables, form parameters of methods/constructors, instance variables, and class variables. To declare a variable as final , use the keyword in the variable declaration final .

1 finalintYES  = 1;

finalThe value of a variable is set only once, and it cannot be re-assigned. There are two ways to initialize final the value of a variable:

    • The initialization is given at the time of declaration.

    • Defer its initialization to a later time.

However, it must be initialized before the variable is read for the first time final .

Click on the link to view the details

Java Final keyword

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.