public abstract class Employee { public abstract void printEmployeeDetails(); }
public class Manager extends Employee { protected String name; protected long empID; protected String designation; public Manager(String name, long empID) { this.name = name; this.empID = empID; } @Override public void printEmployeeDetails() { System.out.println("Name:" + name + " empID:" + empID + " Designation:Manager"); } }
public class Developer extends Employee { protected String name; protected long empID; protected String designation; public Developer(String name, long empID) { this.name = name; this.empID = empID; } @Override public void printEmployeeDetails() { System.out.println("Name:" + name + " empID:" + empID + " Designation:Developer"); } }
public class CompanyDirectory extends Employee { private List employeeList; public CompanyDirectory() { employeeList = new ArrayList<>(); } @Override public void printEmployeeDetails() { for (Employee employee : employeeList) { employee.printEmployeeDetails(); } } public void addEmployee(Employee employee) { employeeList.add(employee); } }
public class CompanyDetails extends CompanyDirectory { private String companyName; public CompanyDetails(String companyName) { this.companyName=companyName; } public void showCompanyName() { System.out.println(this.companyName); } }
public class Company { public static void main(String[] args) { Employee d1 = new Developer("Lenin", 10); Employee d2 = new Developer("Chenchu", 11); Employee d3 = new Developer("Raja", 12); Employee m1 = new Manager("Rakesh", 1); CompanyDetails companyDetails = new CompanyDetails("XYZ"); companyDetails.addEmployee(m1); companyDetails.addEmployee(d1); companyDetails.addEmployee(d2); companyDetails.addEmployee(d3); companyDetails.printEmployeeDetails(); } }