public class Person {
public String name;//姓名
public int age;//年龄
public String birthday;//出生日期
//
//
//public Person{
//
//}
public Person (String name,int age,String birthday){
this.name=name;
this.age=age;
this.birthday=birthday;
}
/**
* 获得对象的信息*/
public String getInfo(){
return "姓名:" + name + "\n年龄:" + age
+ "\n出生日期:" + birthday;
}
}
2
public class Student extends Person{
public String school ;//学校名字
public Student(String name,int age,String birthday,String school){
super(name,age,birthday);
this.school=school;
}
public String getInfo(){
return "姓名:" + name + "\n年龄:"
+ age + "\n出生日期:" + birthday + "\n学校为:"+school;
}
}
/*111
public class Student {
private String name;
private int age;
private String birthday;
private String school;
public Student(String name, int age, String birthday, String school) {
this.name = name;
this.age = age;
this.birthday = birthday;
this.school = school;
}
public String getInfo() {
return "Name: " + name + ", Age: " + age + ", Birthday: " + birthday + ", School: " + school;
}
} */
3
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
//实例化一个叫center的对象
School center=new School();
//初始化center对象
center.school="重庆中心";
center.classNum=10;
center.labNum=20;
//调用center对象的方法
System.out.println(center.getMessage());
}
}
4
public class TestDemo {
public static void main(String[] a){
Student student1 = new Student("鱼",12,"2020-06-11","cqcet");
System.out.println(student1.getInfo());
}
}
/*222
public class TestDemo {
public static void main(String[] args) {
Student student = new Student("鱼", 12, "2001-9-8", "cqcet");
System.out.println(student.getInfo());
}
}*/