package Cai;
import java.util.Scanner;
class Person{//子类的使用
private String name;
private char sex;
private String id;
private String phone;
private String email;
public Person()
{
name="wang";
sex='女';
id="10220202";
phone="123456";
email="qq.com";
}
public Person(String name,char sex,String id,String phone,String email)
{
this.name=name;
this.sex=sex;
this.id=id;
this.phone=phone;
this.email=email;
}
public String getId()
{
return id;
}
public void setEmail(String email)
{
this.email=email;
}
public void setPhone(String phone)
{
this.phone=phone;
}
public String toString1()
{
return name+" "+sex+" "+id+" "+phone+" "+email;
}
}
class Student extends Person
{
private long sNo;
private String sClass;
public Student()
{};
public Student(String name,char sex,String id,String phone,String email,long sNo)
{
super(name,sex,id,phone,email);//父类构造函数形参
this.sNo=sNo;
}
public void setClass(String sClass)
{
this.sClass=sClass;
}
public String toString()
{
super.toString();//调用父类的函数
return"学号"+sNo+" "+"班级"+sClass;
}
}
public class Math {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
Student s1=new Student("刘德华",'男',"2203319","8807","gzdx@126",2000802);
s1.setClass("1班");
System.out.println(s1.toString1());
System.out.println(s1.toString());
}
}
|