colorbox.java
来自「国外的数据结构与算法分析用书」· Java 代码 · 共 37 行
JAVA
37 行
/** A descendant of BasicBox which includes a color attribute. The toString
method is changed to display the new color, and a second constructor is added. */
public class ColorBox extends BasicBox
{
/** The color of the box. */
String color;
/** Constructor using the default color. */
public ColorBox(int l, int w, int h)
{
super(l, w, h);
color = "black";
}
/** Constructor for assigning a color. */
public ColorBox(int l, int w, int h, String c)
{
super(l, w, h);
color = c;
}
/** String representation of this box formed by obtaining the BasicBox string
representation and appending a string representation of the color. */
public String toString()
{
String temp = super.toString();
temp += " Color = " + color + "\n";
return temp;
}
/** Does this box have equal variable values as box other? */
public boolean equals(ColorBox other)
{
return super.equals(other) & color.equals(other.color);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?