看图片,详细要求全在里面了 主要是java用用有参和无参构造并赋值,r1和r2分别调用当中的一个方法并得出结果
2条回答 默认 最新
- Taylor 淡定哥 2023-04-06 02:30关注
package ch4; public class Rect { private double length; private double width; private double area; public Rect() { this.length = 0; this.width = 0; this.area = 0; } public Rect(double length, double width) { this.length = length; this.width = width; this.area = length * width; } public double getArea() { return this.area; } public static void main(String[] args) { Rect r1 = new Rect(); r1.length = 10; r1.width = 5; r1.area = r1.length * r1.width; System.out.println("r1的面积为:" + r1.getArea()); Rect r2 = new Rect(20, 8); System.out.println("r2的面积为:" + r2.getArea()); } }
试一下行不行
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 matlab中使用gurobi时报错
- ¥15 WPF 大屏看板表格背景图片设置
- ¥15 这个主板怎么能扩出一两个sata口
- ¥15 不是,这到底错哪儿了😭
- ¥15 2020长安杯与连接网探
- ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
- ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
- ¥16 mybatis的代理对象无法通过@Autowired装填
- ¥15 可见光定位matlab仿真
- ¥15 arduino 四自由度机械臂