views:

244

answers:

3

which access modifiers which when used with the method makes it available to all the class and subclasses within a package??

+1  A: 

The package access modifier is actually the absence of a modifier. it is also referred to as the 'default' modifier. See here for more info.

akf
+7  A: 

public, protected and the default modifier (which doesn't have a keyword). Everything except private.

For example, suppose the package foo has the following class:

public class MyClass {
   public void method1() { };
   protected void method2() { };
   void method3() { };
   private void method4() { };
}

Then a class foo.SecondClass could call the methods method1, method2 and method3, but not method4.

See the Java tutorial for a useful table of what each modifier allows.

Simon Nickerson
Thanks a lot for the answer
Abhishek Sanghvi
A: 

Turns out protected is actually less "protected" than saying nothing. Both the default package-private and protected allow access from within the package; protected then adds visibility to subclasses outside the package. It is more "protected" than public though.

Ken