Understand the object-oriented thinking of the students, all know that "encapsulation" this basic feature, how to correctly apply the access modifier, just can reflect the good or bad package.
There are four Java access modifiers:
1) Public: Access is the highest, and its decorated classes, class variables, methods all classes are visible.
2) Protected: Its modified classes, class variables, methods are visible in the same package (including homogeneous), and the subclasses of different packages are visible.
3) default modifier, which means that no modifier is added when defining a class, class variable, or method. It is only visible in the same package (including the same).
4) Private: Minimum access, its decorated classes, class variables, and methods are only visible in this class.
Ps:protected and private can only be used in internal classes, and external classes can only be used with public and default.
Give the following table:
For public and private no longer a statement.
Keep in mind the following two points: default focuses on the scope of the package; protected focuses on inheritance.
Protected is relatively special: the same package (containing the same) can access its protected class variables and methods through an instance of the class, except in the same package, only through Super access in the subclass and not through the instance.
Attention to old ginger talk about technology, number: Helojava, or scan the following QR code.
One post per day, technical chicken soup.
Java access modifier