- 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前端開發(fā)技術:HTML、CSS、JavaScript(第3版)
- 深入理解Java7:核心技術與最佳實踐
- 數據結構(C語言)
- 實戰(zhàn)Java高并發(fā)程序設計(第3版)
- Yii Project Blueprints
- Babylon.js Essentials
- HTML+CSS+JavaScript編程入門指南(全2冊)
- Building Dynamics CRM 2015 Dashboards with Power BI
- Vue.js 3應用開發(fā)與核心源碼解析
- OpenCV 3計算機視覺:Python語言實現(xiàn)(原書第2版)
- C++程序設計
- 大學計算機基礎實訓教程
- TypeScript圖形渲染實戰(zhàn):2D架構設計與實現(xiàn)
- C語言程序設計
- UI動效設計從入門到精通