以下是一个简单的Java类,名为`Rectangle`,它包含了两个成员变量`width`和`height`,以及两个方法`area`和`circumference`,用于计算矩形的面积和周长。 ```java public class Rectangle { private double width; private double height; public Rectangle(double width, double height) { this.width = width; this.height = height; } public double getWidth() { return width; } public double getHeight() { return height; } public double area() { return width * height; } public double circumference() { return 2 * (width + height); } } ``` 使用这个类,你可以创建一个新的矩形对象,并调用它的方法来获取矩形的面积和周长。例如: ```java Rectangle rectangle = new Rectangle(10, 5); double area = rectangle.area(); double circumference = rectangle.circumference(); System.out.println("Area: " + area); System.out.println("Circumference: " + circumference); ``` 这将输出: ```makefile Area: 50.0 Circumference: 30.0 ``` [2024-04-11 15:29:23 | AI写代码神器 | 301点数解答]