Ask Question
17 September, 13:12

Determine the best access modifier for each of the following situations: a. A class Employee records the name, address, salary, and phone number. b. An adding method inside of a class BasicMath.

+3
Answers (1)
  1. 17 September, 17:04
    0
    a. Protected

    b. Public

    Explanation:

    There are four acess modifier in Java.

    Default: Acessible only within the same package.

    Public: Can be acessed by any class.

    Private: Acessible only within the class.

    For example, you have a class employee and a private method. This method can only be accessed by an object that is an instance of an employee.

    Protected: Used in classes that extend each other. For example, a class of employees would extend employee.

    So:

    a. A class Employee records the name, address, salary, and phone number.

    The best acesses modifier is protected. A class may extended employee but have the same arguments (name, adress, salary, phone number), so it should also have acess to the method.

    b. An adding method inside of a class BasicMath.

    This method can be used in a variety of packages and projects and classes ... and there is no important information regarding security. So the best method is public.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Determine the best access modifier for each of the following situations: a. A class Employee records the name, address, salary, and phone ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers