Sobes.tech
Junior — Middle+

Employee Data Access Control Module

livecode

Task condition

Develop a set of classes implementing a mechanism for restricting access to employee information.

Base class StaffMember:

  • name — public field, accessible to everyone.
  • position — protected field, visible to the employee and their supervisor.
  • salary — private field, accessible only to the employee themselves.

Class Supervisor (inherits StaffMember):

  • Has the ability to view and modify subordinates' salaries.
  • Can access the position value of other employees.

Class Trainee (inherits StaffMember):

  • Cannot access the salary field, even their own.
  • Only sees name and position of other employees.

Requirements:

  • Strictly adhere to encapsulation principles.
  • Use appropriate access modifiers (public, protected, private).
public class Main {
    public static void main(String[] args) {
        
        Employee manager = new Manager("Alice", "Manager", 5000);
        Employee intern = new Intern("Bob", "Intern");
        
        System.out.println(manager.getName());
        System.out.println(intern.getName());

        // manager changes the intern's salary

        // manager can see the salary

        // intern cannot access the salary
    }
}