If you use protected instead of private, You can create fields that are only accessible within the class and from subclasses.
** ・ public **: Accessable from anywhere ** · protected **: Only accessible from within that class and its child classes ** ・ Private **: Only accessible from within the class (Getters and setters are required to access from outside the class) ** · Default qualifier **: If you do not specify anything for an element, that element's access is considered default and will be available to classes in the same package.
| Access right | public | protected | private | Default | 
|---|---|---|---|---|
| In class | ○ | ○ | ○ | ○ | 
| In a subclass | ○ | ○ | × | × | 
| class,Outside the subclass | ○ | × | × | × |