Java子类继承时,super();的用法是必须的吗?
- 内容介绍
- 文章标签
- 相关推荐
本文共计346个文字,预计阅读时间需要2分钟。
java// (1)定义一个类,描述一个矩形,包含长、宽两种属性和计算面积的方法。class Rectangle { private double length; private double width;
public Rectangle(double length, double width) { this.length=length; this.width=width; }
public double getArea() { return length * width; }}
// (2)编写一个类,继承自Rectangle类,同时描述长方体的长、宽、高属性。
本文共计346个文字,预计阅读时间需要2分钟。
java// (1)定义一个类,描述一个矩形,包含长、宽两种属性和计算面积的方法。class Rectangle { private double length; private double width;
public Rectangle(double length, double width) { this.length=length; this.width=width; }
public double getArea() { return length * width; }}
// (2)编写一个类,继承自Rectangle类,同时描述长方体的长、宽、高属性。

