Is there a way to declare a method "friendly" in Java?

I know that attributes can be set public, friendlyor privateto indicate its visibility.

Is there a way to declare a method friendly? I want it to be available only from class objects of the same package.

Thank you, newbie here: (.

+3
source share
7 answers

Without introducing the visiblity modifier, Java uses the closed area of ​​the package

Pay attention to the following article.

Edit: As mentioned in the comments, there is no way to mark the method as β€œfriendly”. But for your needs, a private package is enough.

+8

- " " " ". , .

, protected , . ( , .)

. Java 6.6.

+6

, / . , .

+4

- .

String myString;

.

+2

, - .

+1

In Java, you have open, secure, batch, and confidential visibility. Package visibility is also known as the default, as you specify it leaving other keywords.

+1
source

If you do not specify any access modifier, then the method will be " package-private ", which sounds the way you want.

0
source

Source: https://habr.com/ru/post/1724609/


All Articles