public class Demo {
public static void main(String[] args) {
Student stu=new Student(9527,"张三",18,175,77);
stu.study();
stu.play();
stu.setId(7749);
stu.setAge(21);
stu.setName("李四");
stu.setHeight(190);
stu.setWeight(85);
stu.study();
stu.play();
}
}
class Person{
private String name;
private int age;
private int height,weight;
public Person() {
this("1",1,1,1);
}
public Person(String name, int age, int height, int weight) {
super();
this.name = name;
this.age = age;
this.height = height;
this.weight = weight;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
if(age<=0||age>=150) {
System.out.println("年龄不规范,启用默认值1");
age=1;
}
this.age = age;
}
public float getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public float getWeight() {
return weight;
}
public void setWeight(int weight) {
this.weight = weight;
}
public String out() {
return "name:"+name+";age:"+age+";height:"+height+";weight:"+weight;
}
}
class Student extends Person{
private int Id;
public Student() {
super();
Id = 0;
}
public Student(int id) {
super();
Id = id;
}
public Student(int id,String name, int age, int height, int weight) {
super(name,age,height,weight);
Id = id;
}
public int getId() {
return Id;
}
public void setId(int id) {
Id = id;
}
public void study(){
System.out.println(out()+"-->在学习...");
}
public void play(){
System.out.println(out()+"-->在玩耍...");
}
public String out() {
return "ID:"+Id+";"+super.out();
}
}