which access modifiers which when used with the method makes it available to all the class and subclasses within a package??
+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
2009-08-29 14:59:53
Thanks a lot for the answer
Abhishek Sanghvi
2009-08-29 15:02:27
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
2009-08-29 21:31:12