-
1.What does it do when written static?
The main benefit of writing static is that the class name. select(strsql);can be called, which is very convenient and does not require the object to be instantiated first, and then the object name. Method;
2.Does writing non-static require instantiation? What is instantiation?
Instantiation is to call the constructor to assign a value to a class object, for example: sqldataadapter da = new sqldataadapter(strsql, con); sqldataadapter da = new sqldataadapter();
da is the class object, sqldataadapter is the constructor, the first is the constructor with parameters, and the second is the default constructor or the parameterless constructor; If sqldataadapter da; Then the da is not instantiated, and the da cannot call any methods and fields.
Non-static methods or variables can only be called by objects, and static methods can only be called by classes, not objects. Static members are classified as owned, or rather owned by all objects.
-
Written statically, it can be applied directly without instantiation.
-
1.Static uses static keyword 2Calling a static method is simply called with the class name, for example:
Static methods do not have direct access to instance member 4Static methods cannot directly call instance method 5Static methods are initialized before being called, and instance methods are initialized when an object is instantiated.
-
The most practical thing is to use static statistical counting, because no matter where you modify it, it is the modified value when you read it, and it is a unique value.
-
static declarations have a copy of both members and methods
-
What is a static class.
A static class is a class that is appropriated directly through a static example without instantiating into an object.
In essence, the static class is process-oriented, because usually it is just a mechanical collection of the original process-oriented ** together, although the result is the existence of the class physique, but the class at this time is more like an emperor's new clothes, so it can be said that the static class is actually dressed in object-oriented skin, doing process-oriented things.
One of the principles of object-oriented design: programming for interfaces, not implementations. What's the difference?
To use an analogy: Putting aside the ** factor, do you prefer a computer with a discrete graphics card or a computer with an integrated graphics card? I think most people will choose a discrete graphics card.
A discrete graphics card can be seen as programming for the interface, while an integrated graphics card can be seen as programming for the implementation. In this way, the shortcomings of implementing programming come to the fore: it loses the possibility of transformation, the flexibility.
Note that in some cases, static lazy bindings can also improve the testability of static classes.
So, there is a good side to static classes, for example, they are very suitable for implementing some stateless utility classes, but most of the time, my subjective consciousness is very clear, use more objects and less static classes, and avoid premature solidification of the system. However, some people say that static analogies are faster than objects and so on, and I haven't compared them, so.
-
1.It's not the fair use of static classes, it's the fair use of static properties. We have no objection to using static classes, and for the existence of similar APIs, static classes that are purely a collection of static methods have their convenience.
2.Static classes are not recommended for things that exist in a non-API way. Especially things that are tied to threads, thread pools, etc., and most of the static properties are non-thread-safe.
3. The static class itself has a context-agnostic feature, so it has a "traversal" nature, which you can call at any time and anywhere, and this feature is exactly what the API needs. For things that are closely related to the context, static classes are not recommended.
-
Static members of a class belong to a class, what is a class? A class is a template for generating objects; Static members belong to a class rather than to an object, and further statically shared members (so it's called share in VB), and any object of this class can be accessed by this static member. Now suppose that a static member can access the variables in an object, and since the static member exists before any concrete object is generated, then the static member will not have access to any of the object's members at all, because the object does not exist at all.
-
1.Because non-static parameters must be assigned after the class has been instantiated, the non-static member has a value.
2.Static methods, on the other hand, belong to the entire class, not just instances of a class.
3.Static methods can be called directly with the class name without creating an instance of the class with the new keyword, and if the non-static parameters are accessed when the static methods in the class are directly called by the class name, the non-static parameters do not exist in memory at all. So accessing something that doesn't exist will cause an error, so the arguments must also be static, and static variables will be generated in memory as soon as they start.
Xinlei (Qing) Zhang Weiping.
Creation is silent but affectionate, and every time it is cold, it is born in spring. >>>More
The happiness is theirs, I have nothing" is from Zhu Ziqing's "Moonlight on the Lotus Pond", the original sentence is "The excitement is theirs, I have nothing." ” >>>More
Based on the starlight criterion,In 2000, Tom Hanks was shipwrecked and lived there so that the sound effect was recorded.,Last year, Sean Penn went to Tweak for wilderness survival activities.,Personal translation,Please forgive me for the mistakes.,Tweak has the meaning of twisting but I don't think it makes sense here.,Could it be a place name?
Prove it. The words of enlightenment are the perceptions of those who have come over, and the realm of kung fu in the heart, and they have learned thousands of sentences, which are not substantial, but only the wit of the mouth and pen, and they cannot be used for half of it.
Mirrors are a must-have for cars, and they are configured so that you don't have to turn your head drastically to look at the situation behind you.