继承的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);
    }
    
    
}

猜你喜欢

转载自www.cnblogs.com/lvzhiqi/p/10859701.html