总结,由于在上一篇帖子中详细介绍了接口,对于抽象类和接口都有了较为深入的理解,所以今天的作业可以比较轻松地完成。
作业题一:
1>创建Person接口:public interface Person {
public void setData(String sID, String speciality,String name, String sex, Date birthday);
public String getData();
2>建立Student类:
public class Student implements Person{
/**
* @param args the command line arguments
*/
private String sID;
private String speciality;
private String name;
private String sex;
private Date birthday;
@Override
public void setData(String sID, String speciality, String name, String sex,
Date birthday) {
this.sID = sID;
this.speciality = speciality;
this.name = name;
this.sex = sex;
this.birthday = birthday;
}
@Override
public String getData() {
return "Student [sID=" + sID + ", speciality=" + speciality + ", name="
+ name + ", sex=" + sex + ", birthday=" + birthday + "]";
}
作业题二
1> 为柱体的底面设计一个接口Geometry:
public interface Geometry {
public double PI=3.1415;