new Garbage();
new Garbage();
new Garbage();
new Garbage();
System.gc();
}
}
new Garbage();
new Garbage();
new Garbage();
new Garbage();
System.gc();
}
}编译运行:

如果不用System.gc();则运行结果不会显式地回收垃圾,它只有在内存不足等情况时才自动回收垃圾。
调用System.gc();可以显式地回收垃圾。
■ 关于接口(Interface)
编写一个接口程序:

interface Sport...{
void run();
void jump();
}
class Athlete implements Sport...{
void run()...{
System.out.println("Running!");
}
void jump()...{
System.out.println("Jumping");
}