[java]代码库
Person
package exam3;
public class Person {
private String name;
private char sex;
private String id;
private String phone;
private String email;
public Person()
{
System.out.println("调用了个人构造方法Person()");
}
public Person(String name,char sex,String id)
{
this.name=name;
this.sex=sex;
this.id=id;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getId()
{
return id;
}
public void setId(String id)
{
this.id = id;
}
public char getSex()
{
return sex;
}
public void setSex(char sex)
{
this.sex = sex;
}
public String getPhone()
{
return phone;
}
public void setPhone(String phone)
{
this.phone = phone;
}
public String getEmail()
{
return email;
}
public void setEmail(String email)
{
this.email = email;
}
public String toString()
{
return this.getName()+this.getSex()+this.getId();
}
}
class Student extends Person
{
private String sClass;
private long sNo;
public Student()
{
System.out.println("调用了学生构造方法Student()");
}
public Student(String name,char sex,String id,long sNo)
{
super(name,sex,id);
this.sNo=sNo;
System.out.println(sClass);
}
public long getsNo()
{
return sNo;
}
public void setsNo(long sNo)
{
this.sNo=sNo;
}
public String getsClass() {
return sClass;
}
public void setsClass(String sClass) {
this.sClass = sClass;
}
public String toString()
{
return "姓名"+this.getName()+"性别"+this.getSex()+"ID"+this.getId()+"学号"+this.getsNo()+"邮箱"+this.getEmail()+"联系方式"+this.getPhone();
}
public void setSex(String string) {
// TODO 自动生成的方法存根
}
}
TestStudent
package exam3;
public class TestStudent {
public static void main(String[] args)
{
Student s1=new Student();
s1.setName("刘德华");
s1.setSex('男');
s1.setId(" 1111111111 ");
s1.setsNo(2008002);
s1.setEmail(" gzdx@126.com");
s1.setPhone(" 88078549 ");
System.out.println(s1.toString());
}
}