Static objects and non-static objects

Source: Internet
Author: User

What is the difference between a Java static object and a non-static object??

Static object non-static object
are collectively owned by the class. Is independent of the class,
The memory space is fixed space allocated within each subordinate class
Allocates the space of the static object and then allocates the space to the non-static object, that is, the initialization order is first static and non-static.


What is the difference between a Java static object and a static property and a static method?
All three are similar to the general object properties and methods, and can be regarded as static properties of static objects. But the landlord should pay attention to the non-static method is not allowed to use static properties. Static methods also cannot use non-static properties (the property is not a parameter.) A parameter is usually a new value or object that is temporarily created in the method. property is the information that is partially declared by a class declaration).


Why first declare a static object, static Lefthand left, and then instantiate the object in the main function left=new Lefthand ();?
Because any object is initialized before it is used, new is initialized after the object is allocated space.


What are the benefits of Java static objects??
My personal understanding is that static objects allow common attributes to be shared between classes of the same type, which is synchronous and not new, saving space


1, the static object data in the global is unique, a change is changed. If you want to deal with something that is unique throughout the program, it's a good way to get static.
2, non-static things you modify after you just modified his own data, but will not affect other similar objects of data.
3. Both static and non-static objects are objects and are objects that are instantiated. The difference is that the data representation of 2 is different from the way it is stored.
4. Static Benefits:
Easy reference. For variables of a common type, use the class name directly. static method name or class name. A static variable name can be referenced and can be modified directly without getter and setter methods.
Keep the data unique. This data is unique globally, modifying any of his places, where all the applications are used will be reflected in the changes to the data.
Effectively reduce unnecessary waste.

Static objects and non-static objects

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.