Ask Question

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.

+2
Answers (1)
  1. 26 November, 01:28
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers