//静态变量,static可以修饰变量,方法,代码块
public class StaticCountTest1 {
public static int count=0;//声明并初始化静态变量count
public int selcount=0;
public static int a1=10;
public static int a2;
public StaticCountTest1(){//构造方法中count和selcount自增1,a1和a2均赋值为20
count++;
selcount++;
a1=a2=20;
}
public static void main(String[] args) {
//创建3个对象
StaticCountTest1 s1=new StaticCountTest1();
StaticCountTest1 s2=new StaticCountTest1();
StaticCountTest1 s3=new StaticCountTest1();
//打印成员变量的值
System.out.println("静态变量count="+StaticCountTest1.count);
System.out.println("对象s1,s2,s3的selcount值分别为:"+s1.selcount+","+
s2.selcount+","+s3.selcount);
System.out.println("静态变量a1="+StaticCountTest1.a1+",静态变量a2="+StaticCountTest1.a2);
}
}
//静态变量,static可以修饰变量,方法,代码块public class StaticCountTest1 { public static int count=0;//声明并初始化静态变量count public int selcount=0; public static int a1=10; public static int a2; public StaticCountTes