Static methods for using static in Java

Source: Internet
Author: User

As with static variables, we can also use the static modification method, called a static method or a class method. In fact, the main method we've been writing about is static methods. The use of static methods such as:

Operation Result:

Need to note:

1 static members can be called directly in a static method, but not non-static members directly. such as:

if you want to invoke a non-static variable in a static method, you can access the non-static variable by creating the object of the class and then through the object . Such as:

2, in the ordinary member method, you can directly access the same kind of non-static variables and static variables , as follows:

3, static methods can not directly invoke non-static methods, you need to access the non-static method through the object. such as:

Static methods for using static in Java

Related Article

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.