From the course: Oracle Java Certification: 3. Methods and Inheritance

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Method access modifiers

Method access modifiers - Java Tutorial

From the course: Oracle Java Certification: 3. Methods and Inheritance

Start my 1-month free trial

Method access modifiers

- [Instructor] In Java, where a member method can be called is controlled by its access of visibility modifiers. This table shows the four different levels of visibility in an increasing order from top to bottom. A private member has the least amount of visibility. It can only be referenced inside the class in which it is defined. If no access modifier is used, the method is considered default or package private, which means it can be referenced in all the classes in the same package in which the method is defined. Note that the protected modifier is a misnomer, because it is less protected or more visible than default. A protected method can be accessed from classes in the same package and all the subclasses that may be in other packages. Public means public. A public method can be invoked anywhere an object or class reference can be found. Let's look at example. Here we have a Main class that uses three other…

Contents