The Static keyword in Java

Source: Internet
Author: User

Features of the Static keyword
    1. Loaded with the load of the class;
    2. Precedence over the existence of objects;
    3. Be shared by all objects of the class;
    4. Can be called by the class name;
Memory Diagram Construction code block

Constructing a code block takes precedence over the construction method execution, and creating an object executes once;

publicclass User {    privateint age;    publicUser(int age) {        System.out.println("构造方法执行");        this.age = age;    }    publicintgetAge() {        return age;    }    publicvoidsetAge(int age) {        this.age = age    }    {         System.out.println("构造代码块执行");    }    }

Output Result:

Constructing code block execution
Construction method Execution

Final keyword
    1. In inheritance, when a method of the parent class is modified with final, the subclass inherits the parent class, and the subclass cannot modify the final decorated method in the parent class;

The Static keyword 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.