Java矩形类继承Shape

package com.itheima;
/**
 * @author SAMSUNG
 */
public class Rectangle extends Shape{
    private int lo;
    private int wi;
    public void Rectangle()
    {

    }
    public void Rectangle(int l,int w)
    {
        this.lo=l;
        this.wi=w;
    }
    public  void setLoAndwi(int l,int w)
    {
        this.lo=l;
        this.wi=w;
    }
    public void getLo()
    {
        System.out.println(this.lo);
    }
    public  void getWi()
    {
        System.out.println(this.wi);
    }
    @Override
    public double getArea()
    {   return this.wi*this.lo;
    }
    public static void main(String[]args)
    {
        Rectangle r1=new Rectangle();
        r1.setLoAndwi(3,4);
        System.out.println("矩形的面积是"+r1.getArea());
    }
}

posted @ 2019-10-13 20:15  AmosAlbert  阅读(238)  评论(0编辑  收藏  举报