- Java 9 Programming By Example
- Peter Verhas
- 175字
- 2021-07-02 23:37:35
Modifiers
Methods, constructors, fields, interfaces, and classes can have access modifiers. The general rule is that in case there is no modifier, the scope of the method, constructor, and so on, is the package. Any code in the same package can access it.
When the private modifier is used, the scope is restricted to the so-called compilation unit. This means the class that is in one file. What is inside one file can see and use anything declared to be private. This way, inner and nested classes can have access to each other's private variables, which may not really be a good programming style, but Java permits that.
The opposite of private is public. It extends the visibility to the whole Java program, or at least to the whole module, if the project is a Java 9 module.
There is a middle way: protected. Anything with this modifier is accessible inside the package and also in classes that extend the class (regardless of package) that the protected method, field, and so on, is in.
- Web程序設計及應用
- Azure IoT Development Cookbook
- 數據結構(Java語言描述)
- Learn Programming in Python with Cody Jackson
- 算法訓練營:提高篇(全彩版)
- OpenStack Orchestration
- 運用后端技術處理業務邏輯(藍橋杯軟件大賽培訓教材-Java方向)
- Unity 2018 Augmented Reality Projects
- Buildbox 2.x Game Development
- JavaScript+jQuery網頁特效設計任務驅動教程
- Mockito Essentials
- Julia High Performance(Second Edition)
- Penetration Testing with the Bash shell
- HTML5游戲開發實戰
- Android 游戲開發大全(第二版)