研马原 2021-10-15 16:38 采纳率: 57.1%
浏览 65
已结题

Java构造方法,类与对象

img

  • 写回答

3条回答 默认 最新

  • 关注
    
    public class Test {
        public static void main(String[] args) {
            Rectangle rectangle = new Rectangle(30, 40);
            double computCircum = rectangle.computCircum();
            System.out.println("computCircum = " + computCircum);
            double computArea = rectangle.computArea();
            System.out.println("computArea = " + computArea);
        }
    }
    
    
    class Rectangle {
        private double width;
        private double height;
    
        public Rectangle() {
        }
    
        public Rectangle(double width, double height) {
            this.width = width;
            this.height = height;
        }
    
        public double computCircum() {
            return (width + height) * 2;
        }
    
        public double computArea() {
            return width * height;
        }
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 10月23日
  • 已采纳回答 10月15日
  • 创建了问题 10月15日