JAVA final keyword, definition of constants

Source: Internet
Author: User

Final (final) is a modifier
1, final can be modified classes, functions, variables (member variables, local variables)
2, the final modified class can not be inherited by other classes
3, the final modified method (function) can not be rewritten
4, the final modified variable (attribute) is not allowed to be re-assigned, final in the modification of the variable must be assigned, the final modified variable, we call the constant

Define constants: Final type uppercase constant name = constant value
Constant naming specification: All letters should be capitalized, if the name is made up of multiple words, the words are separated by _

 Public class test{    publicstaticvoid  main (string[] args) {        final String Title    =    "title";    // defines a constant of type string         System.out.println (TITLE);}    }

JAVA final keyword, definition of constants

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.