// Employee class (base class) class Employee { private String name; private int employeeId; public Employee(String name, int employeeId) { this.name = name; this.employeeId = employeeId; } public String getName() { return name; } public int getEmployeeId() { return employeeId; } public void displayDetails() { System.out.println("Employee ID: " + employeeId); System.out.println("Name: " + name); } } // Faculty class (inherits from Employee) class Faculty extends Employee { private String department; private String designation; public Faculty(String name, int employeeId, String department, String designation) { super(name, employeeId); this.department = department; this.designation = designation; } public String getDepartment() { return department; } public String getDesignation() { return designation; } @Override public void displayDetails() { super.displayDetails(); System.out.println("Department: " + department); System.out.println("Designation: " + designation); } } // Staff class (inherits from Employee) class Staff extends Employee { private String role; public Staff(String name, int employeeId, String role) { super(name, employeeId); this.role = role; } public String getRole() { return role; } @Override public void displayDetails() { super.displayDetails(); System.out.println("Role: " + role); } } // UniversityProgram class (main program) public class UniversityProgram { public static void main(String[] args) { // Creating instances of Faculty and Staff Faculty facultyMember = new Faculty("John Doe", 101, "Computer Science", "Professor"); Staff staffMember = new Staff("Jane Smith", 201, "Administrative Assistant"); // Displaying details of Faculty and Staff System.out.println("Faculty Details:"); facultyMember.displayDetails(); System.out.println(); System.out.println("Staff Details:"); staffMember.displayDetails(); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter