📄 rectangle1.java
字号:
//【例3.8】 抽象类与抽象方法。
public class Rectangle1 extends PlaneGraphics1 //长方形类
{
protected double length; //长度
protected double width; //宽度
public Rectangle1(double length, double width)
{ //构造方法
super("长方形");
this.length = length;
this.width = width;
}
public Rectangle1(double width) //正方形是长方形的特例
{
super("正方形");
this.length = width;
this.width = width;
}
public Rectangle1()
{
this(0,0);
}
public void setLength(double length)
{
this.length = length;
}
public void setWidth(double width)
{
this.width = width;
}
public double getLength()
{
return this.length;
}
public double getWidth()
{
return this.width;
}
public double area() //计算长方形面积,实现父类的抽象方法
{
return this.width * this.length;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -