|
What is a protected method |
|
|
A protected method can be called by any subclass within its class, but not by unreleated classes.
Declaring a method protected defines its access level. The other options for declaring visibility are private and public. If undeclared, the default access level is package.
The protectedMethod() method is a private method in the following class:
public class MyClass {
private void privateMethod() {
System.out.println("I am private method");
}
void packageMethod() {
System.out.println("I am package method");
}
protected void protectedMethod() {
System.out.println("I am protected method");
}
public void publicMethod() {
System.out.println("I am public method");
}
|
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.