Java Access Modifiers - A Method Available To Subclasses And Packages
4 answers
public
, protected
and the default modifier (which has no keyword). Everything except private
.
For example, suppose a package foo
has the following class:
public class MyClass {
public void method1() { };
protected void method2() { };
void method3() { };
private void method4() { };
}
Then the class foo.SecondClass
can call methods method1
, method2
and method3
, but not method4
.
See the Java tutorial for a helpful table of what each modifier allows.
+9
source to share