Java keyword final, static usage summary

Source: Internet
Author: User

Original link: Java keyword final, static some points

1. Final

The  final class cannot be inherited, there are no subclasses, and the method in the final class defaults to the final final method, which cannot be overwritten by the method of the quilt class, but can be inherited by the final member variable to represent the constant, which can only be assigned once, Cannot be changed after assignment final can not be used to modify the construction method private can not be overridden by the class method, the private type method by default is the final type of   final modified variables have three kinds: static variables, instance variables and local variables, Represents three types of constants, respectively. Note: 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 ensures that the blank final must be initialized before it is used, regardless of the situation.   2. Static static means "global" or "static", which modifies member variables and member methods, and can also form statically static blocks of code, but there is no concept of global variables in the Java language.   member variables and member methods that are modified by static are independent of any object of that class. That is, it does not depend on class-specific instances and is shared by all instances of the class. As long as this class is loaded, the Java virtual machine can find them based on the class name in the method area of the run-time data area. Therefore, a static object can be accessed before any of its objects are created, without referencing any objects.   Static member variables and member methods that are decorated with public are essentially global variables and global methods, and when declaring the object city of its class, do not generate a copy of the static variable, but all instances of the class share the same static variable.  -class member variable   -static variable (class variable): Static modifier   -instance variable      : no static modifier-local variable   3. Static and final use  static final to decorate member variables and member methods, which can be understood as "global variables"   for variables, which means that once a value is given it cannot be modified and is accessible through the class name. For methods, the representation is not overwritten and can be accessed directly through the class name.   Note: For instance constants that are static and final modified, the instance itself can no longer be changed, but for instance variables of some container types (for example, ArrayList, HashMap), the container variable itself cannot be changed, but the object stored in the container can be modified.   Other Reference Links: Java keyword final, static usage summaryStatic and final keywords

Java keyword final, static usage summary (GO)

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.