第13周学习总结

 class Rectangle1{
        private double width;

        public void setWidth(double width) {
            this.width = width;
        }

        public void setHeight(double height) {
            this.height = height;
        }

        private double height;
        private int count;
        double C(){
            double C=(width+height)*2;
            return C;
        }
        double S(){
            double S=width*height;
            return S;
        }
        Rectangle1(){
            count++;
        }
        Rectangle1(double width,double height){
            this.width=width;
            this.height=height;
            count++;
        }
        void  show(){
            System.out.println(this.width);
            System.out.println(this.height);
        }
        public int getCount(){
            return count;
        }
        static void count(){
            Rectangle1 R=new Rectangle1();
            System.out.println("对象个数为"+R.getCount());
        }
        Rectangle1 compare(Rectangle1 rectangle1,Rectangle1 rectangle2){
            if (rectangle2.S()> rectangle1.S()){
                return rectangle2;

            }else {
                return rectangle1;
            }
        }

    }
    public class newRectangle {
        public static void main(String[] args) {
            Rectangle1 R=new Rectangle1(2,6);
            Rectangle1 R1=new Rectangle1();
            R1.setHeight(24);
            R1.setWidth(28);
            System.out.println(R.S());
            System.out.println(R1.S());
            System.out.println(R.C());
            System.out.println(R1.C());
            System.out.println("面积大的为"+R.compare(R, R1));
            System.out.println(R.getCount()+R1.getCount());
        }

    }

该题分别采用了有参构造法和无参构造法,调用时需要单独调用

this关键字的作用:可以用于指定访问当前对象的成员变量,成员方法

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值