class Person{ public String name; public String getName(){ return name; } } class Employee extends Person{ public int employeeNumber; public int getEmployeeNumber(){ return employeeNumber; } } class Manager extends Employee{ public String responsibilities; public String getResponsibilities(){ return responsibilities; } } public class Exam { public static void main(String args[]){ Employee Li = new Employee(); Li.name="Li Ming"; Li.employeeNumber=123456; System.out.println(Li.getName()); System.out.println(Li.getEmployeeNumber()); Manager he = new Manager(); he.name="He Xia"; he.employeeNumber=543469; he.responsibilities="Internet project"; System.out.println(he.getName()); System.out.println(he.getResponsibilities()); } }
时间: 2023-06-07 20:09:39 浏览: 72
Java Enum和String及int的相互转化示例
你的问题是关于Java类继承的。代码定义了一个Person类,一个Employee类,一个Manager类。Employee和Manager都是Person的子类,Manager是Employee的子类。代码在main方法中创建了Employee和Manager对象,然后打印它们的姓名和员工编号或职责。
阅读全文