2016/09/21 Java Keyword final

Source: Internet
Author: User

1.final class

The final class cannot be inherited, there are no subclasses, and the methods in the final class are final by default.

The final class cannot be inherited, so the member methods of the final class have no chance of being overwritten, and the default is final.

2.final method

The final method cannot inherit from the quilt class, but can inherit.

3.final variables

A constant is represented by a final decorated member variable that cannot be changed once a value is given.

When the final variable is defined, it can be declared without giving the initial value, which is also called the final blank, and the compiler will ensure that the blank final must be initialized before it is used, regardless of the situation.

4.final parameters

When the function parameter is the final type, you can read the parameter using it, but you cannot change the value of the parameter.

public class Test {public  static void Main (string[] args) {           new Test (). F1 (2);   }   public void F1 (final int i) {           i++;    I is the final type, and the value is not allowed to change.           System.out.print (i);   } }
Final local variable I cannot be assigned. It must is blank and not using a compound assignment

2016/09/21 Java Keyword final

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.