- 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.
- Cocos2d-x游戲開發:手把手教你Lua語言的編程方法
- Python自動化運維快速入門
- Python應用輕松入門
- 大學計算機基礎(第2版)(微課版)
- Apache Kafka Quick Start Guide
- Angular開發入門與實戰
- Lighttpd源碼分析
- Mastering Elasticsearch(Second Edition)
- 創意UI:Photoshop玩轉APP設計
- RubyMotion iOS Develoment Essentials
- Java并發編程:核心方法與框架
- C#面向對象程序設計(第2版)
- The Statistics and Calculus with Python Workshop
- 程序員的英語
- Practical Time Series Analysis