Java Static keyword

Source: Internet
Author: User

1.static member variables
    • A static variable is also called a class variable, and all instances access the same variable
    • static final is used to define constants, usually named with uppercase and underlined.
 Packagecn.lz.base;/*** Static keywords *@authorlzzz **/ Public classJ17100803 {intID = 1; Static intIDD = 2;  Public Static voidMain (string[] args) {J17100803 J1=NewJ17100803 (); J17100803 J2=NewJ17100803 (); J1.idd+ = 1; J2.idd+ = 1; J1.id+ = 1; J2.id+ = 1; System.out.println (j1.id); //2System.out.println (J1.idd);//4System.out.println (j2.id);//2System.out.println (J2.idd);//4System.out.println (J17100803.idd);//can be accessed by classname. Variable name    }}
2.static method

The static method of the public adornment can be accessed through the class name. Variable name

3.static Domain
    • The static field is only executed once during the class load time
    • {} non-static initialization code block is executed before the constructor
4. Static Import
 Package cn.lz.base; Import static java.lang.math.*; /**  @author*/Publicclass  J17100803    {  publicstaticvoid  main (string[] args) {        System.out.println (ABS (//  }    }

Java Static keyword

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.