在给定的代码中,程序员没有定义像getArea
这样的方法,并且没有提到括号中的哪个参数是“width”而哪个是“height”。
我是Java新手。请帮我理解代码。
这是从qazxsw poi采取的代码
http://docs.oracle.com/javase/tutorial/java/javaOO/objects.html
该程序创建,操作和显示有关各种对象的信息。这是输出:
rectOne的宽度:100 rectOne的高度:200 rectOne的面积:20000 X rect的位置:23 Y rectTwo的位置:94 X rectTwo的位置:40 Y rectTwo的位置:72
查看它在网站上链接的其他课程。
您将需要所有三个源文件来编译此程序。
public class CreateObjectDemo {
public static void main(String[] args) {
// Declare and create a point object and two rectangle objects.
Point originOne = new Point(23, 94);
Rectangle rectOne = new Rectangle(originOne, 100, 200);
Rectangle rectTwo = new Rectangle(50, 100);
// display rectOne's width, height, and area
System.out.println("Width of rectOne: " + rectOne.width);
System.out.println("Height of rectOne: " + rectOne.height);
System.out.println("Area of rectOne: " + rectOne.getArea());
// set rectTwo's position
rectTwo.origin = originOne;
// display rectTwo's position
System.out.println("X Position of rectTwo: " + rectTwo.origin.x);
System.out.println("Y Position of rectTwo: " + rectTwo.origin.y);
// move rectTwo and display its new position
rectTwo.move(40, 72);
System.out.println("X Position of rectTwo: " + rectTwo.origin.x);
System.out.println("Y Position of rectTwo: " + rectTwo.origin.y);
}
}
Point方法在getArea
类
提到的Rectangle或Point类不是java.awt.Rectangle和java.awt.Point类。它们是Rectangle
和Point类,它们的链接在代码之前给出。
Rectangle
编辑:从您刚刚显示的链接,它说它正在使用这些类:
`Rectangle` and `Point` are java built-in classes.