在给定的代码中,没有getArea的定义。但是没有错误?怎么样?

问题描述 投票:-1回答:3

在给定的代码中,程序员没有定义像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

java core jdeveloper
3个回答
0
投票

查看它在网站上链接的其他课程。

您将需要所有三个源文件来编译此程序。

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); } }

CreateObjectDemo

Rectangle

Point方法在getArea


0
投票

提到的Rectangle或Point类不是java.awt.Rectangle和java.awt.Point类。它们是RectanglePoint类,它们的链接在代码之前给出。


-1
投票
Rectangle
Those methods are already defined. Check the documentation: http://docs.oracle.com/javase/7/docs/api/java/awt/Rectangle.html http://docs.oracle.com/javase/7/docs/api/java/awt/Point.html

编辑:从您刚刚显示的链接,它说它正在使用这些类:

`Rectangle` and `Point` are java built-in classes.
© www.soinside.com 2019 - 2024. All rights reserved.