People、Student和主类;People类中有2个成员变量name和age,2个方法setName和show方法;Student类是People类的子类,包含1个成员变量department和一个方法setDepartment;主类中要求创建Student对象,调用以上3个方法并给参数赋值。
https://blog.csdn.net/weixin_43478250/article/details/101361396
class People {
private String name;
private String age;
public void setName(String name) {
this.name = name;
}
public void show(String name,String age){
System.out.println("输出:" +name+","+age);
}
public static void main(String[] args) {
Student student=new Student();
student.setName("li");
student.setDepartment("销售");
student.show("li","18");
}
}
class Student extends People{
private String department;
public void setDepartment(String department) {
this.department = department;
}
}
两个类的创建我就不写了,你在主类中People people = new Student();创建一个People的子类对象,剩下的直接调用方法及赋值就行