2016/09/21 Java keyword final, 2016 final

Source: Internet
Author: User

2016/09/21 Java keyword final, 2016 final
1. final class

The final class cannot be inherited and has no subclass. The methods in the final class are final by default.

The final class cannot be inherited. Therefore, the member methods of the final class have no chance to be overwritten. By default, they are all final.

2. final Method

The final method cannot be inherited by the quilt class, but can be inherited.

3. final variable

The final modified member variable is used to represent constants, and the value cannot be changed once given.

When final variables are defined, they can be declared first without initial values. This variable is also called final blank. In any case, the compiler will ensure that the blank final must be initialized before use.

4. final Parameters

When the function parameter is of the final type, you can read and use this parameter, but you cannot change the value of this parameter.

Public class Test {public static void main (String [] args) {new Test (). f1 (2);} public void f1 (final int I) {I ++; // I is of the final type and cannot be changed. system. out. print (I );}}
The final local variable i cannot be assigned. It must be blank and not using a compound assignment

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.