-2

I met a function which declared :

 void functionName()

without any prefix (private, public, protected, static).

It's not very important thing just interesting me how it's work (like a public or private). I know it's easy to test but maybe it have some other benefits.

Bosko Mijin
  • 3,287
  • 3
  • 32
  • 45
  • The access modifier is `default`, you should google Java access modifiers. Any method can have a `default` access modifier, not just `void` return-type methods. – Kon Oct 20 '14 at 14:47

3 Answers3

3

Visit Controlling Access to Members of a Class:

Modifier    Class   Package  Subclass   World
---------------------------------------------
public      Y       Y        Y          Y
protected   Y       Y        Y          N
no modifier Y       Y        N          N     You are here
private     Y       N        N          N

When you have no modifier, it'll be available in class and package, not in subclasses and world.

Maroun
  • 94,125
  • 30
  • 188
  • 241
0

The access modifier for that method is called the default access modifier.

It will allow access within same class and package.

See documentation here.

Mena
  • 47,782
  • 11
  • 87
  • 106
0

This question might be beneficial to look over. It not only explains the default (or lack of) access modifiers, but reviews all access modifiers.

In Java, difference between default, public, protected, and private

Community
  • 1
  • 1