package override;
public class OverrideExersice {
public static void main(String[] args){
Person p1 = new Person("smith",20);
Student p2 = new Student("jack",20,"1234",88.5);
System.out.println(p1.say());
System.out.println(p2.say());
}
}
package override;
public class Person {
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public Person() {
}
public Person(String name, int age) {
setAge(age);
setName(name);
}
public String say(){
return "自我介绍:" + " 名字:" + name + " 年龄:" + age;
}
}
package override;
public class Student extends Person{
private String id;
private double score;
public Student() {
}
public Student(String id, double score) {
setId(id);
setScore(score);
}
public Student(String name, int age, String id, double score) {
super(name, age);
this.id = id;
this.score = score;
}
public String say(){
return super.say() + " id:" + id + " 分数:" + score;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
}