在给定的代码中,程序员没有定义类似getArea
的方法,并且没有提到括号中的哪个参数是“width”而哪个是“height”。
我是Java新手。请帮我理解代码。
该代码来自http://docs.oracle.com/javase/tutorial/java/javaOO/objects.html
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);
}
}
该程序创建,操作和显示有关各种对象的信息。这是输出:
rectOne的宽度:100
rectOne的高度:200
rectOne面积:20000
X rect的位置:23
Y rectTwo的位置:94
X rect的位置:40
Y rectTwo的位置:72
答案 0 :(得分:0)
答案 1 :(得分:0)
答案 2 :(得分:-1)
`Rectangle` and `Point` are java built-in classes.
<德尔>
这些方法已经定义。
查看文档:
http://docs.oracle.com/javase/7/docs/api/java/awt/Rectangle.html
http://docs.oracle.com/javase/7/docs/api/java/awt/Point.html
德尔>
编辑:从您刚刚显示的链接,它说它正在使用这些类:
http://docs.oracle.com/javase/tutorial/java/javaOO/examples/Point.java
http://docs.oracle.com/javase/tutorial/java/javaOO/examples/Rectangle.java