Objects 对象
A typical Java program creates many objects, which as you know, interact by invoking methods. Through these object interactions, a program can carry out various tasks, such as implementing a GUI, running an animation, or sending and receiving information over a network. Once an object has completed the work for which it was created, its resources are recycled for use by other objects.
一个典型的 Java 程序创建许多对象,如您所知,这些对象通过调用方法进行交互。通过这些对象交互,程序可以执行各种任务,如实现 GUI、运行动画,或通过网络发送和接收信息。一旦一个对象完成了创建它的工作,它的资源将被回收供其他对象使用。
Here’s a small program, called CreateObjectDemo
, that creates three objects: one Point
object and two Rectangle
objects. You will need all three source files to compile this program.
这是一个叫做 CreateObjectDemo
的小程序,它创建了三个对象:一个 Point
对象和两个 Rectangle
对象。您需要所有三个源文件来编译这个程序。
public class CreateObjectDemo {
public static void main(