学习三角形类的编程,继承自通用类
SimpleGeometricObject.java
package ClassExtend;
import java.util.Date;
//通用类,几何对象的父类
public class SimpleGeometricObject {
private String color;//对象的颜色
private boolean isFilled;//对象是否填充颜色
private Date dateCreated;//对象创建的日期
//无参的默认构造方法
SimpleGeometricObject(){
this ("white",false);
}
//带特定颜色与填充值的构造方法
SimpleGeometricObject(String newColor,boolean newIsFilled){
color = newColor;
isFilled = newIsFilled;
dateCreated = new Date();
}
//返回颜色
public String getColor() {
return color;
}
//设置新的颜色
public void setColor(String newColor) {
color = newColor;
}
//返回填充属性
public boolean getFilled() {
return isFilled;
}
//设置新的填充属性
public void setFilled(boolean newIsFilled) {
isFilled = newIsFilled;
}
//返回创建日期
public Date getDateCreated() {
return dateCreated;
}
//返回对象的字符串表述
public String toString() {
return dateCreated+color+isFilled;
}
}
<