Explore the Java keyword final

Source: Internet
Author: User

1. final modifies the class. It indicates restricted inheritance, that is, the class is the final class and cannot be inherited. It is located at the bottom of the inheritance structure, which is equivalent to a leaf. All the methods are final by default. 2. The final modifier indicates that the method cannot be overwritten ). 3. final modifier variable. This variable can only be assigned once. If both final and static are modified, the variable must be assigned a value while being defined. If final is not in combination with static, you can assign the value assignment task to the constructor when defining the variable. 4. final cannot modify the interface. Think about it. If the interface cannot be implemented, what is the significance of defining the interface? 5. final cannot modify the class together with abstract. The reason is similar. This is because the abstract class is intended to inherit the subclass. 6. The final modifier parameter cannot be modified within the lifecycle (method body. (Including the original type and reference type) 7. final cannot be simultaneously and abstract modifier, reason 4, 5. 8. final cannot modify the constructor.

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.