编程输出性别信息,要求定义一个People类,在该类中声明name,sex和age成员变量,并定义outputSex()方法

2024-11-17 04:56:48
推荐回答(1个)
回答(1):

public class Person { private static String name; private static String sex; private static int age; Person(String name, int age) { this.name = name; this.age = age; } public void print() { System.out.print("名字:" + name + " 性别:" + sex + " 年龄:" + age + " "); } } public class Student extends Person { private static String school; private static String department; private static String studentno; Student(String name, int age, String school, String department, String studentno) { super(name, age); this.school = school; this.department = department; this.studentno = studentno; } public void print() { super.print(); System.out.println("学校是:" + school + " 系是:" + department + " 学号是:" + studentno); } }