You are developing a payroll system. How would you design a class for storing employee details and ensuring that some sensitive information (like salary) cannot be accessed directly from the object?

  • Define private instance variables for employee details, including salary, and provide public get and set methods for accessing and modifying the salary.
  • Define public instance variables for employee details and make the salary variable final.
  • Define public static variables for employee details, including salary, and use the 'protected' access modifier.
  • Use the 'volatile' keyword for sensitive information like salary.
To ensure that sensitive information like salary cannot be accessed directly from the object, you should define private instance variables for employee details and provide public get and set methods for salary. This follows the principle of encapsulation, which restricts direct access to sensitive data. The other options do not provide adequate security for sensitive information.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *