Java子类构造中如何正确调用父类构造函数super()?
- 内容介绍
- 文章标签
- 相关推荐
本文共计349个文字,预计阅读时间需要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类,同时描述长方体的长、宽、高属性。
本文共计349个文字,预计阅读时间需要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类,同时描述长方体的长、宽、高属性。

