标签:
class Person{
private String name;
private String addr;
private char sex;
private int age;
public void setName(String name){
this.name = name;
}
public void setAddr(String addr){
this.addr = addr;
}
public void setSex(char sex){
this.sex = sex;
}
public void setAge(int age){
this.age = age;
}
public Person(String name,String addr,char sex,int age){
this.setName(name);
this.setAddr(addr);
this.setSex(sex);
this.setAge(age);
}
public Person(String name,int age){
this.setName(name);
this.setAge(age);
}
public Person(){}
public String getInfo(){
return "name: "+this.name+
"; addr: "+this.addr+
"; sex: "+this.sex+
"; age: "+this.age;
}
public void say(){
System.out.println(this.getInfo());
}
}
class Student extends Person{
private int math;
private int english;
public void setMath(int math){
this.math = math;
}
public void setEnglish(int english){
this.english = english;
}
public Student(String name,String addr,char sex,int age,int math,int english){
super(name,addr,sex,age);
this.math = math;
this.english = english;
}
public Student(String name,int age){
super(name,age);
}
public Student(){};
public String getInfo(){
return super.getInfo()+
"; math: "+this.math+
"; english: "+this.english;
}
public void say(){
super.say();
}
}
public class Test{
public static void main(String[] args){
Person per1 = new Person("小赵",22);
Person stu1 = new Student("小钱","北京",‘M‘,20,80,90);
Student stu2= new Student("小孙","河北",‘M‘,21,85,95);
per1.say();
stu1.say();
stu2.say();
}
}
标签:
原文地址:http://www.cnblogs.com/chendi0912/p/5367614.html