标签:name 案例 demo r++ work i++ for dem static
案例一:
public class A{
//static int number = 0;
int number = 0;
public A(){
number++;
System.out.println("数字:"+number);
}
}
public class Test{
public static void main(String [] args){
for(int i = 0 ; i < 10 ; i++){
A a = new A();
}
}
}
案例二:
public class Demo{
public static void main(String[] args){
Worker w1 = new Worker("Jack");
w1.startWork();
System.out.println("当前开工的总人数:"+Worker.totle);
Worker w2 = new Worker("Rose");
w2.startWork();
System.out.println("当前开工的总人数:"+Worker.totle);
}
}
public class Worker {
String name;
static int totle = 0;
public Worker(String name){
this.name = name;
}
public void startWork(){
totle++;
System.out.println("工人"+this.name+"开工了");
}
}
标签:name 案例 demo r++ work i++ for dem static
原文地址:https://www.cnblogs.com/Listener-wy/p/13358193.html