What is the default scope of a method in Java?

Joe Fontana picture Joe Fontana · Apr 3, 2009 · Viewed 136.9k times · Source

If I type:

 void doThis(){
     System.out.println("Hello Stackoverflow.");
 }

what is the default scope of doThis()?

Public? Protected? Private?

Answer

Esko Luontola picture Esko Luontola · Apr 3, 2009

The default scope is package-private. All classes in the same package can access the method/field/class. Package-private is stricter than protected and public scopes, but more permissive than private scope.

More information:
http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html
http://mindprod.com/jgloss/scope.html