package com.demo;
class Person1 {
private String name ;
private String addr ;
private char sex ;
private int age ;
// 省略getter与setter方法
// 注意无返回值类型
public Person1() {}
public Person1(String name, String addr, char sex, int age) {
this.name = name;
this.addr = addr;
this.sex = sex ;
this.age = age ;
}
public Person1(String name, String addr) {
this(name,addr,'男',0); //调用本类中的四参构造
}
public String getInfo() {
return "姓名:" + this.name + ",地址:" + this.addr + ",性别:" + this.sex + ",年龄:" + this.age ;
}
}
class Student1 extends Person1 {
private double math ;
private double English;
public Student1() {}
public Student1(String name, String addr, char sex, int age, double math, double English) {
super(name,addr,sex,age) ; //调用父类中的四参构造
this.math = math ;
this.English = English ;
}
public Student1(String name, String addr) {
super(name,addr); //调用父类中的两参构造
}
public String getInfo() {
return super.getInfo() + ",数学成绩:" + this.math + ",英语成绩:" + this.English ;
}
}
public class Stu {
public static void main(String[] args) {
Student1 st = new Student1("一只瓶子a", "北京", '女', 2, 90.0, 99.6);
System.out.println(st.getInfo());
}
}