Static is the meaning of statics. Used to decorate member variables and member methods, which are static-decorated member variables and member methods that are independent of any object of the class. That is, it does not depend on class-specific
Static statically-keywordStatic properties and methods can be called without instantiating the class, directly in the way they are used 类名::方法名 . Static properties do not allow an object to be called with an operator.Class Car { private static
Static Key WordsSolve two kinds of problems 1, Just want to allocate a single storage space for a particular domain without thinking about how many objects to create, or even creating any objects at all 2, You want a method not to
1. Static methodsIn general, defining a method in a class is static, which means that you do not need an object of this class to call this methodThe method declared as static has the following limitations:· They can only invoke other static methods.·
In addition to the use of regular classes and methods in PHP, access control, static keywords, static variables can be local variables can also be global variables, when a program segment is completed, the static variable does not disappear, it
The static keyword is used in C + + and Java to decorate statically member variables and member functionsAn example of an ordinary JavaBeanclass aa{ int A; Static int b; Geta/seta; // omit Getset here getb/Setb;}If you create an object
1.static member variables
A static variable is also called a class variable, and all instances access the same variable
static final is used to define constants, usually named with uppercase and underlined.
Packagecn.lz.base;/***
There are four usage scenarios in the Java language: member variables, member methods, code blocks, and inner classes(1) static member variableIn Java, you can achieve the effect of global variables by statin keyword modifiers. Static modified
(1) The function body static variable scope is the function body, different from the auto variable, the memory of the variable is allocated only once, so its value at the next call will still maintain the last value;(2) The static global variable
1. The first and most important article is to introduce it: hide. (static function, static variable all available)When multiple files are compiled at the same time, all global variables and functions that do not have a static prefix have global
The static method is the method without this. A non-static method cannot be called inside a static method, which in turn is possible. It is also possible to invoke the static method only through the class itself, without creating any objects. This
Static (statically)
Can be used to modify properties, methods, blocks of code (or initialization blocks), inner classes
Static modifier property (class variable):
1. All objects created by the class share this property
2.
Members in a class can be divided into ordinary and static members, and functions can be divided into ordinary functions and static functions. Ordinary members can only be owned by each object alone, whereas static members are common to all objects
Three features summary :
share :
allocating memory in the global data area will only have one copy.shared by function (where static local variables are called multiple times)To be shared by (all) objects of the class in which the static method or
The static keyword in PHP and the difference with the self keyword. The static keyword in PHP and the difference with the self keyword. This article mainly introduces the static keyword in PHP and the difference with the self keyword, this article
As for properties and methods declared as static in a class, this does not describeAnother important feature of the scope of variables in PHP is the static variable (the statics variable). Static variables exist only in the local function domain and
There are two uses for the static of C + +: Static in process programming and static in object oriented programming. The former is applied to ordinary variables and functions and does not involve classes; the latter mainly describes the role of
1. The first and most important article is to introduce it: hide. (static function, static variable all available)When multiple files are compiled at the same time, all global variables and functions that do not have a static prefix have global
Looking at the PHP manual, I found the following code:
Copy Code code as follows:
function Test ()
{
static $count = 0;
$count + +;
Echo $count;
if ($count Test ();
}
$count--;
}
?>
The results of the
Many beginners may not understand the use of static methods, here I say my understanding:
The call to the static method does not depend on the creation class object
The This keyword is not used in the static method because no objects need
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.