• 继承的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);
        }
        
        
    }
  • 相关阅读:
    man 1 find
    ubuntu20.04输入密码登录不进去
    界面控件DevExpress WinForms皮肤编辑器的这个补丁,你了解了吗?
    UI控件Telerik UI for WinForms新主题——VS2022启发式主题
    干货分享|DevExpress v22.1原版帮助文档下载集合
    Linux下VCS搭建Oracle集群并使用NBU备份到VTL带库真实环境实验
    技术技巧MYSQL常用命令
    sparkSQL实验5.3
    foldByKey和combineByKey
    Scala实验4.1
  • 原文地址:https://www.cnblogs.com/lvzhiqi/p/10859701.html
Copyright © 2020-2023  润新知