static关键字:类变量和类方法
类变量(静态变量)–被该类的所有实例对象所共享。
类方法(静态方法)–方法声明前加上static关键字。
1>、
class A{
static int count = 0;
A(){
count++;
System.out.println(“#”+count+” “+”对象被创建”);
}
}
public class Dian{
public static void main(String[] args){
A a01 = new A();
A a02 = new A();
A a03 = new A();
A a04 = new A();
A a05 = new A();
}
}
2>、
class A{
int count = 0;
A(){
count++;
System.out.println(“#”+count+” “+”对象被创建”);
}
}
public class Dian{
public static void main(String[] args){
A a01 = new A();
A a02 = new A();
A a03 = new A();
A a04 = new A();
A a05 = new A();
}
}