qq_52741197 2021-06-21 01:47 采纳率: 100%
浏览 10
已采纳

java问题,请求解答

 

  • 写回答

2条回答 默认 最新

  • CSDN专家-sinJack 2021-06-21 01:54
    关注

    定义一个类,其中包含两个属性,并且提供对外访问的方法,提供一个默认的无参构造方法和两个参数的构造方法,以及输出方法。

    如有帮助,请采纳。

    public class Square extends Shape{
        private int height;
        private int width;
    
        public void setHeight(int height) {
            this.height = height;
        }
    
        public void setWidth(int width) {
            this.width = width;
        }
    
        public int getHeight() {
            return height;
        }
    
        public int getWidth() {
            return width;
        }
        public Square(String colour) {
            super(colour);
        }
        public Square(String colour, int height, int width) {
            super(colour);
            this.height = height;
            this.width = width;
        }
    
        public void print(){
            System.out.println("Square of height:"+height+",width:"+width);
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?