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.
Loading...
Related Quiz
- Which of the following methods returns the number of rows affected by the DML operation?
- What is the difference between a synchronized block and a synchronized method?
- The ________ keyword is used to declare objects that cannot change.
- Which exception might be thrown when opening a file for reading?
- Which of the following statements about the 'this' keyword is incorrect?