关于一个接口的问题,很迷惑,弱弱的问一下,谢谢
package fouth;public class InterfaceTest {
public static void main(String[] args) {
Student astudent=new Student("tom","123456");
//astudent.setAddress("beijing");
astudent.setSex("men");
System.out.println(astudent);
}
}
interface Person{
String getName();
String getSex();
String getBirthday();
String getAddress();
//void setAddress(String strAddress);
}
class Student implements Person{
private String strName="";
private String strSex="";
private String strNumber="";
private String strBirthday="";
private String strSpeciality="";
private String strAddress="";
public String getSex() {
return strSex;
}
public void setSex(String strSex) {
this.strSex = strSex;
}
public String getBirthday() {
return strBirthday;
}
public void setBirthday(String strBirthday) {
this.strBirthday = strBirthday;
}
public String getSpeciality() {
return strSpeciality;
}
public void setSpeciality(String strSpeciality) {
this.strSpeciality = strSpeciality;
}
public String getAddress() {
return strAddress;
}
public String getName() {
return strName;
}
public String getNumber() {
return strNumber;
}
public Student(String strName, String strNumber) {
super();
this.strName = strName;
this.strNumber = strNumber;
}
public String toString(){
String information="学生姓名="+strName+",学号="+strNumber;
if(!strSex.equals("")){
information+=",性别="+strSex;
}
if(!strBirthday.equals("")){
information+=",出生年月="+strBirthday;
}
if(!strSpeciality.equals("")){
information+=",专业="+strSpeciality;
}
if(!strAddress.equals("")){
information+=",籍贯="+strAddress;
}
return information;
}
//public void setAddress(String strAddress) {
//this.strAddress=strAddress;
}
}
其中Stduent类显示“已经定义的类型”,找不出原因,而且在接口中定义的方法setAddress()也实现不了,迷惑迷惑。。。