JAVA程序

来源:百度知道 编辑:UC知道 时间:2024/05/15 16:08:52
//: Garbage.java
// Demonstration of the garbage
// collector and finalization

class Chair {
static boolean gcrun = false;
static boolean f = false;
static int created = 0;
static int finalized = 0;
int i;
Chair() {
i = ++created;
if(created == 47)
System.out.println("Created 47");
}
protected void finalize() {
if(!gcrun) {
gcrun = true;
System.out.println(
"Beginning to finalize after " +
created + " Chairs have been created");
}
if(i == 47) {
System.out.println(
"Finalizing Chair #47, " +
"Setting flag to stop Chair creation");
f = true;
}
finalized++;
if(finalized >= created)
System.out.println(
"All " + finalized + " finalized");

args是你进行编译时附带的参数,比如说:
java Garbage canshu1 canshu2;
那么args[0]就是“canshu1”,args[1]就是“canshu2”

args是命令行参数的字符串集合,0表示第一个参数,length==0表示没有参数。

通上