A method's visibility is known as method scope.
Scope
A method's visibility is known as
method scope. We can say that it defines whether a object can invoke as well as
any subclass can override the method or not. The scope are generally used as per
the need of the program or application, e.g. if a method intended to be access
only by the own class of the method then we make the visibility private
Modifier |
Can be Accessed By |
public | The method can be access by any class. |
protected | The defining method can be access by the same package, class and subclass. |
private | This type of method can be invoked by the owner class. |
No Modifier | It also works as same as protected. |