因此,在深入学习课程之前,我试图理解压倒一切。我看过 TheNewBoston (bucky) 解释压倒一切,但我不确定我是否做得对。有人会检查我并让我走上正确的道路吗?
我不记得 bucky 必须在他的超类中保护他的任何实例变量。但是当我构建我的子类时,eclipse 让我将我的实例变量转换为受保护的。
超类联系人:
public class Contacts
{
protected String fname;
protected String lname;
protected String email;
protected String phone;
public Contacts(String fname, String lname, String email, String phone)
{
this.fname=fname;
this.lname=lname;
this.email=email;
this.phone=phone;
}
public String getfname()
{
return fname;
}
public void setfname(String first)
{
this.fname=first;
}
public String getlname()
{
return lname;
}
public void setlname(String last)
{
this.lname=last;
}
public String getemail()
{
return email;
}
public void setemail(String e)
{
this.email=e;
}
public String getphone()
{
return phone;
}
public void setphone(String num)
{
this.phone=num;
}
public String getFullName()
{
String full=fname+" "+lname;
return full;
}
子类朋友:
public class Friend extends Contacts
{
private String dob;
public Friend(String fname, String lname, String email, String phone)
{
super(fname, lname, email, phone);
}
public String getDob()
{
return dob;
}
public void setDob(String dob)
{
this.dob = dob;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString()
{
return fname+", "+lname+", "+email+", "+phone+", "+dob;
}
}
子类 BusinessAssociate:
public class BusinessAssociate extends Contacts
{
private String title;
private String position;
private String company;
private String full;
public BusinessAssociate(String fname, String lname, String email,
String phone)
{
super(fname, lname, email, phone);
}
public String getTitle()
{
return title;
}
public void setTitle(String title)
{
this.title=title;
}
public String getCompany()
{
return company;
}
public void setCompany(String company)
{
this.company=company;
}
public String getPosition()
{
return position;
}
public void setPosition(String position)
{
this.position=position;
}
/* (non-Javadoc)
* @see Contacts#getFullName()
*/
@Override
public String getFullName()
{
full=title+" "+fname+" "+lname;
return full;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString()
{
return full+", "+email+", "+phone+", "+company+", "+position;
}
}