zoukankan      html  css  js  c++  java
  • 继承的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);
        }
        
        
    }
  • 相关阅读:
    制作ubuntu容器完整步骤
    linux系统python3安装pip
    ssh连接服务器提示拒绝了密码
    ubuntu中vi编辑中按键错误
    虚拟机ubuntu连不上网
    NOIP2020退役记
    【NOIp2020游记】
    loki简单安装配置使用
    .net下com调用支持x86/x64
    nginx 504 Gateway Time-out
  • 原文地址:https://www.cnblogs.com/lvzhiqi/p/10859701.html
Copyright © 2011-2022 走看看