- 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.
- UNIX編程藝術
- 數(shù)據(jù)結構與算法JavaScript描述
- Django Design Patterns and Best Practices
- Internet of Things with Intel Galileo
- Scala編程實戰(zhàn)(原書第2版)
- Spring Boot進階:原理、實戰(zhàn)與面試題分析
- 高級語言程序設計(C語言版):基于計算思維能力培養(yǎng)
- Solr Cookbook(Third Edition)
- 響應式架構:消息模式Actor實現(xiàn)與Scala、Akka應用集成
- C語言從入門到精通
- 從零開始:UI圖標設計與制作(第3版)
- Hands-On Kubernetes on Windows
- Illustrator CC平面設計實戰(zhàn)從入門到精通(視頻自學全彩版)
- Python從入門到精通(第3版)
- Kotlin Programming By Example