Final usage of Java

Source: Internet
Author: User

Java final is a very flexible existence that can be used in three places: classes, variables, methods.

Class:

The final use of the class above is equivalent to the use of sealed in C #. is to avoid inheriting from other classes.

Variable:

When final is used on a variable, it is equivalent to the const modifier of C #, which means that when the final modifier is a value type, the value of the value type cannot be changed, and if a reference type is modified, the variable can no longer refer to another object.

Method:

When the final modification method is present, if there is an inherited relationship, the final decorated method cannot be overridden in the subclass. This is similar to the virtual and override of C #, but the methods in C # are not virtual by default. The Java method is virtual by default.

Final usage of Java

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.