The difference between static and non-static in Java

Source: Internet
Author: User

See on the Internet, feel good, own notes down, later forget the convenient to see:

A non-static method is relative to a static method. static methods use the static keyword to indicate that a non-static method does not have this keyword.

The biggest difference between them is that their life cycle is different, the static method belongs to the global method, when the static method is accessed for the first time, the memory will be resident until the whole system is destroyed;

The non-static method is related to the class, and only if the class in which the method resides is instantiated, the method is accessed, and the method of destroying the class is destroyed.

The difference in the life cycle determines how they are called, and static methods are invoked using the (class name. Method name) instead of the static method (the new class name (). Method name) to invoke.
It is also related to that static methods cannot invoke non-static methods and properties . This is also better understood after understanding the differences in their life cycles, because static methods have a longer life cycle than non-static methods and properties, and when non-static methods and properties are called, non-static methods and properties are destroyed, causing the program to fail.

The difference between static and non-static 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.