Static purpose: Defining a statically member, static method
static feature : Belongs to class; No matter how many objects are instantiated, the static domain occupies only one memory
Call method : Call directly with class name or object instantiated by class
A static field in a class consists of two kinds, one is a static member and one is a static method. They are all belong to the class, not belong to
of an object. They can be called directly with the class name.
Of course, you can also use objects to invoke. But from the beginning to the end, they only exist in one memory. Static methods can be used in classes where the other
Static methods and static members, non-static methods and Non-static members cannot be invoked, and non-static methods can be arbitrarily invoked without restriction.
* * Verify the static domain in the class no matter how many objects are created, there is only one instance of the static field: W
*thinking in Java Test 2.8
* @author: Wolfofsiberian
*
* * Public
class tij_test2_8{
static int a=0;
Public Tij_test2_8 () {
a++;
System.out.println ("a=" +a);
}
public static void Main (String args[]) {
tij_test2_8 test1=new tij_test2_8 ();
System.out.println ("test1.a=" +test1.a);
Tij_test2_8 test2=new tij_test2_8 ();
System.out.println ("test2.a=" +test2.a);
Tij_test2_8 test3=new tij_test2_8 ();
System.out.println ("test3.a=" +test3.a);
Tij_test2_8 test4=new tij_test2_8 ();
System.out.println ("test4.a=" +test4.a);
Tij_test2_8 test5=new tij_test2_8 ();
System.out.println ("test5.a=" +test5.a);
tij_test2_8.a=100;
System.out.println ("test1.a=" +test1.a);
System.out.println ("test2.a=" +test2.a);
System.out.println ("test3.a=" +test3.a);
System.out.println ("test4.a=" +test4.a);
System.out.println ("test5.a=" +test5.a);
}
The results of the execution are as follows, and the modification of member A in the constructor is reflected in each newly created object. Use a class to call a, modify its value,
The modified values are reflected in all of the objects.
Test1.a=1
test2.a=2
Test3.a=3
Test4.a=4
Test5.a=5
test1.a=100
test2.a=100
test3.a=100
test4.a=100
test5.a=100