Now that we understand inheritance, we can try to explain the visibility modifiers, such as private and public. There is still one more concept we need to fully understand visibility, but we at least now enough to talk about it now.
| Situation | public | default | protected | private protected | private |
|---|---|---|---|---|---|
| Accessible to non-subclass | Yes | Yes | Yes | No | No |
| Accssible to subclass | Yes | Yes | Yes | No | No |
| Inherited by subclass | Yes | Yes | Yes | Yes | No |
This table is abbreviated to contain only what we've learned so far. Notice that with what we know, public, default and protected are the same. Later we'll see the differences.
Default is the visibility assigned to a class, method or variable if you do not explicitly assign it some other visibility, such as private or public.
Return to the Main Menu.