• 继承的super的用法


    package test1;
    
    
    public class Rectangle1 {
        private float length;
        private float width;
        float S=length*width;//矩形的底面积
        public Rectangle1(float length,float width) {
            this.length=length;
            this.width=width;
        }
        public Rectangle1() {
            // TODO 自动生成的构造函数存根
        }
        public float getLength() {
            return length;
        }
        public void setLength(float length) {
            this.length = length;
        }
        public float getWidth() {
            return width;
        }
        public void setWidth(float width) {
            this.width = width;
        }
    
        public void printMessage(){
            System.out.println("长为:"+length+"宽为:"+width+"面积为:"+length*width);
        }
        public static void main(String[] args) {
            Rectangle1 a=new Rectangle1(10,20);
            a.printMessage();
            Cubiod1 b=new Cubiod1(10,20,30);
            b.printMessage();
        }
    }
        
    class Cubiod1 extends Rectangle1{
        private float height;//长方体的高
    
        public Cubiod1(float length, float width,float height) {
            super(length, width);
            this.height = height;
            // TODO 自动生成的构造函数存根
        }
        public Cubiod1() {
            // TODO 自动生成的构造s函数存根
        }
        
        public float getLength() {
            return super.getLength();
        }
        public void setLength(float length) {
            super.setLength(length);
        }
        public float getWidth() {
            return super.getWidth();
        }
        public void setWidth1(float width) {
            super.setWidth(width);
        }
        public float getHeight() {
            return height;
        }
        public void setHeight(float height) {
            this.height = height;
        }
    
        float V=super.getLength()*super.getWidth()*height;//长方体的体积
        public void printMessage(){
            System.out.println("长为:"+super.getLength()+"宽为:"+super.getWidth()+"高为"+height+"体积为:"+super.getLength()*super.getWidth()*height);
        }
        
        
    }
  • 相关阅读:
    char类型到底是有符号还是无符号
    GNU C编译器的gnu11和c11
    kotlin之包
    mysql 各个版本驱动jar包
    网络优化
    Android 布局优化
    Android之MVVM开发模式
    Android蓝牙开发技术学习总结
    Android 电量优化
    Android中图片优化
  • 原文地址:https://www.cnblogs.com/lvzhiqi/p/10859701.html
Copyright © 2020-2023  润新知