编写测试主类testclass创建employee,manager类的对象
时间: 2024-05-15 07:19:04 浏览: 137
好的,让我为您编写测试主类testclass来创建employee和manager类的对象。以下是示例代码:
```java
public class TestClass {
public static void main(String[] args) {
// 创建Employee对象
Employee employee = new Employee("John", 50000);
employee.display();
// 创建Manager对象
Manager manager = new Manager("David", 80000, "IT department");
manager.display();
}
}
// Employee类
class Employee {
private String name;
private double salary;
public Employee(String name, double salary) {
this.name = name;
this.salary = salary;
}
public void display() {
System.out.println("Employee name: " + name);
System.out.println("Employee salary: " + salary);
}
}
// Manager类继承Employee类
class Manager extends Employee {
private String department;
public Manager(String name, double salary, String department) {
super(name, salary);
this.department = department;
}
public void display() {
super.display();
System.out.println("Manager department: " + department);
}
}
```
请注意,这只是示例代码,您可以根据需要进行更改。
阅读全文