The difference between static and non-static functions

Source: Internet
Author: User

Static methods that use the static modifier are class methods that belong to the entire class, and the code snippets in memory are allocated and loaded with the definition of the class, whereas non-static methods are methods that belong to a specific object, and when the object is created, it has a private code snippet for this method in the object's memory. When you reference a static method, you can prefix it with the object name, or you can use the class name. eg. ClassA instantiates an object objecta,
A static method is defined in ClassA: Run (). can be performed using Classa.run () or Objecta.run ().

A non-static method can access both static data members and non-static data members, while static methods can access static data members only, and non-static methods can access both static and non-static methods, while static methods can only access static data methods. A special note is the main method in the static method, which acts as the entry point for the program, and has only one in each program.

The difference between static and non-static functions

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.