public class Accessproperty { int i=47;//change plus static int i=47; public void called () { System.out.println ("Call () method"); for (int i=0;i<3;i++) { System.out.println (i+ ""); if (i==2) { System.out.println ("\ n") ; }}} Public Accessproperty () { }public static void Main (string[] args) {//TODO auto-generated method stub Accessproperty t1=new Accessproperty (); Accessproperty t2=new Accessproperty (); t2.i=60; System.out.println ("The first instance object invokes the result of the variable I:" +t1.i++); T1.call (); System.out.println ("The second instance object invokes the result of the variable I:" +t2.i); T2.call (); }}
Output to
The first instance object invokes the result of the variable I: 47
Calling the call () method
0
1
2
The second instance object invokes the result of the variable I: 60
Calling the call () method
0
1
2
2. Use static
The first instance object invokes the result of the variable I: 60
Calling the call () method
0
1
2
The second instance object invokes the result of the variable I: 61
Calling the call () method
0
1
2
Java Learning---The difference between a static member variable and a general member variable