0

I'm learning Java language. A little confused about the modifier.

Sometimes I saw method inside a class with no modifier, like this for example:

public class example0{       
    void example1(){
        System.out.println();
    }
}

Normally there is modifier like public or private in front of void in the method to set visibility.

Why sometimes there`s no modifier in front the method like the example above?

What is that mean compare to the one with public or private?

Sufian
  • 5,997
  • 14
  • 60
  • 111
Leo
  • 61
  • 8

2 Answers2

0

It means that the method has a default access, which means it will be accessible only within the package in which the nesting class is located.

Konstantin Yovkov
  • 59,030
  • 8
  • 92
  • 140
0

This means that you have a defaultmodifier and it is accesible for the class and the package. Here is a Table with a description out of this link: Click.

Modifier    | Class | Package | Subclass | World
————————————+———————+—————————+——————————+———————
public      |  y    |    y    |    y     |   y
————————————+———————+—————————+——————————+———————
protected   |  y    |    y    |    y     |   n
————————————+———————+—————————+——————————+———————
no modifier |  y    |    y    |    n     |   n    **also known as package-private**
————————————+———————+—————————+——————————+———————
private     |  y    |    n    |    n     |   n

y: accessible
n: not accessible
Community
  • 1
  • 1
MrT
  • 580
  • 2
  • 17
  • Why didn't you just give the link to that question in the comment. http://stackoverflow.com/questions/215497/in-java-whats-the-difference-between-public-default-protected-and-private. It helps others coming here. – Sorter Aug 14 '15 at 07:58