What modifier should you use on a class so that a class in the same package can access it but a class (including a subclass) in a different package cannot access it?A. publicB. privateC. protectedD. Use the default modifier.

Respuesta :

Answer:

Option (B) is the correct answer of this question.

Explanation:

In the Private access modifier we can access the property and field within the package or class we cannot accessing the member outside the class .

  • We use private keyword for declaring the private access modifier.
  • In the public access modifier we accessing the property outside the class so it's a incorrect option .
  • In the protected access modifier we access the property of class package and subpackage both so it's a incorrect option.
  • The default modifier is incorrect it not follow the given scenario so it's incorrect.