What are the drawbacks of static methods?

Source: Internet
Author: User

Answer 1: In some systems, static methods are used frequently to improve system performance. I think so :)

A 2: it cannot be upgraded. Rewriting depends on the purpose of a software product.

Answer 3: You do not need to instantiate it for convenience.ProgramSystem resources are occupied during compilation and running.

A 4: static attributes and methods are fully loaded into the memory when the program starts, regardless of whether these methods and attributes are used in the future. Even if no one accesses the program, this part of the memory will not be released. In addition, the data of all the static attributes seen by the visitor is almost the same. For example, if user a sets the username attribute, during User B's access, the username is still the one set by user. If this feature is used in fixed data, there will be no major problems, such as the connection string.

Answer 5: static methods/data members belong to a class rather than an object, so they do not need to be instantiated when called. Static methods and static data members are equivalent to shared variables. Because all objects in this class are shared, it is a good choice to define this type when you need to share data. Once a class is defined (it is not necessary to instantiate the object), all the static members of the class are loaded into the memory (not when the program is started, but not when the class is not defined) the scope of a static member is the same as that of its class.

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.