What is the default scope of a method in Java?

JavaScope

Java Problem Overview


If I type:

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

what is the default scope of doThis()?

Public? Protected? Private?

Java Solutions


Solution 1 - Java

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

Solution 2 - Java

Anything defined as package private can be accessed by the class itself, other classes within the same package, but not outside of the package, and not by sub-classes.

See this page for a handy table of access level modifiers...

Solution 3 - Java

Without an access modifier, a class member is accessible throughout the package in which it's declared. You can learn more from the Java Language Specification, §6.6.

Members of an interface are always publicly accessible, whether explicitly declared or not.

Solution 4 - Java

The default scope is "default". It's weird--see these references for more info.

Solution 5 - Java

Java 8 now allows implementation of methods inside an interface itself with default scope (and static only).

Solution 6 - Java

If you are not giving any modifier to your method then as default it will be Default modifier which has scope within package.
for more info you can refer http://wiki.answers.com/Q/What_is_default_access_specifier_in_Java

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJoe FontanaView Question on Stackoverflow
Solution 1 - JavaEsko LuontolaView Answer on Stackoverflow
Solution 2 - Javauser15299View Answer on Stackoverflow
Solution 3 - JavaericksonView Answer on Stackoverflow
Solution 4 - JavaMichael HarenView Answer on Stackoverflow
Solution 5 - JavashivView Answer on Stackoverflow
Solution 6 - Javauser1011455View Answer on Stackoverflow