Static means that statically decorated member variables and member methods are independent of any object of that class. That is, it does not depend on class-specific instances and is shared by all instances of the class. Static means you can use it without instantiating it. 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 is actually the primary use of the static method. "Although this remark only illustrates the special character of the static method, it is possible to see the basic role of the static keyword, in short, one sentence to describe it: it is convenient to make a call (method/variable) without creating an object. Static variables are also known as static variables, except that the static variables are shared by all objects, only one copy in memory, and are initialized only when the class is first loaded. Instead of static variables, which are owned by an object, are initialized when the object is created, there are multiple copies, and the replicas owned by each object do not affect each other.
Example://Calculate the number of objects produced. If count is not static, each resulting object is initialized.
Package test;
public class Static1 {
public static int count=0;
Public Static1 ()
{
count++;
}
public static void Main (String args[])
{
Static1 s1=new Static1 ();
Static1 s2=new Static1 ();
System.out.println (Static1.count);//can be called directly with the class name.
}
}
This article is from the "11897435" blog, please be sure to keep this source http://11907435.blog.51cto.com/11897435/1856920
Java modifier Word static