Java's final keyword

Source: Internet
Author: User

Final keyword (can be read, not writable, read-only)

1. The value of the final variable cannot be changed

①, final member variable

②, final local variable (formal parameter)//meaning "argument" is not allowed to change once it is passed into my method

2. Final method can not be rewritten

3. Final class can not be inherited

Is there a final class in the Java API? A: Yes, such as the String class. The API is declared as: Public final class string{};

 Public classtestfinal{ Public Static voidMain (String args[]) {T T=NewT (); //t.i=2; //cannot assign a value to the final variable i                    }}classt{Final intI =1;}classtt{ Public Final voidoverRide () {}}classTTTextendstt{/*Public final void override () {//appears: Override () in TTT cannot overwrite override ()} in TT*/}Final classtttt{}/*class TTTTT extends tttt{//will appear: cannot inherit from the final class TTTT}*/

Java's 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.