Employee.java
public class Employee { private String name; private int age; private boolean male; private double salary; Employee(String name, int age, boolean male, double salary) { this.name = name; this.age = age; this.male = male; this.salary = salary; } String displayEmpInfo() { return ("===" + name + "'s Personal Info=== " + "Name: " + name + " " + "Age: " + age + " " + "Male: " + male + " " + "Salary: " + salary + " "); } }
Manager.java
public class Manager extends Employee { private String department; Manager(String name, int age, boolean male, double salary, String department) { super(name, age, male, salary); this.department = department; } String displayEmpInfo() { return super.displayEmpInfo() + "Department: " + department + " "; } }
Drive.java
import java.util.ArrayList; public class Drive { public static void main(String[] args) { Employee empMan1 = new Employee("Jerry", 45, true, 4500); Employee empWoman1 = new Employee("Elaine", 40, false, 3500); Manager manMan1 = new Manager("George", 50, true, 8000, "Sales"); ArrayList<Employee> staff = new ArrayList<>(); staff.add(empMan1); staff.add(empWoman1); staff.add(manMan1); for (int i = 0; i < staff.size(); ++i) { System.out.println(staff.get(i).displayEmpInfo()); } // for (Employee n: staff) // { // System.out.println(n.displayEmpInfo()); // } } }