0

Is there any way we can hide a method only for some classes in the same package? For example, this is my file structure:

MainFolder
   - A.java
   - B.java -> This class has some methods which can be accessed by 'A' and 'C' but not by 'D'
   - C.java
   - D.java

Moving them to the other package can be helpful but I was curious about it being in the same package as I didn't want to make new folders for a single file and would like to keep it organised.

  1. Is it possible to be achieved?
  2. If yes, then how?
Sambhav Khandelwal
  • 3,585
  • 2
  • 7
  • 38
  • No, this is not possible. You're choice of visibility is between package private (default access) or private, and one is too wide, and the other is too restrictive. – Mark Rotteveel Oct 16 '22 at 10:15

0 Answers0