Description of final and static keywords in Java

Source: Internet
Author: User
  1. Final

    The FIANL keyword can decorate classes, methods, and variables.

    A. Modifier classes

    The final decorated class, which has no subclasses and cannot be inherited by the class.

    B. Modification methods

    Final can modify the method. The final decorated method cannot be overridden.

    c. modifier variables

    The final modified variable, which is a constant and can only be assigned once, is a member variable and a local variable.


  2. Static

    A. Static is used to decorate members, which can be member variables and member methods.

    B. Members that are modified by static can be called directly by the class. Class name. Static member

    C. Loads as the class loads and disappears as the class disappears. When a class is loaded, there is a static member that exists before the object. The static member life cycle is long.

    D. be shared by all objects.

    E. Static variables (that is, class variables) exist in the method area, and non-static variables (instance objects) exist in heap memory.

    F. Static methods can only invoke static members. (because static members take precedence over object existence, non-static members do not exist when static methods are generated, so non-static cannot be called)

    G. The This super keyword cannot be used in a static method. Because this super represents an object, the object does not yet exist.

    H. Static advantage: Save space by storing the shared data of the object in a separate space. Disadvantages, the life cycle is too long, access has limitations.

This article is from the "Sima" blog, make sure to keep this source http://9274590.blog.51cto.com/9264590/1695658

Description of final and static keywords in 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.