1 public class VolitileTest { 2 volatile static int count=0; 3 public static void main(String args[]){ 4 5 for(int i=0;i<1000;i++){ 6 new Thread(new Runnable() { 7 public void run() { 8 count++; 9 } 10 } 11 ).start(); 12 } 13 System.out.println(count); 14 } 15 }
1 public class Wanmei { 2 public static void test(Object object){ 3 System.out.println("my object"); 4 } 5 6 public static void test(String s){ 7 System.out.println("my String"); 8 } 9 10 public static void main(String args[]){ 11 test(null); 12 } 13 }
运行结果:
第一道:0-1000之间的数了
第二道:my String