- 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.
- SQL Server 2012數(shù)據(jù)庫技術(shù)及應(yīng)用(微課版·第5版)
- Practical Data Science Cookbook(Second Edition)
- .NET 4.0面向?qū)ο缶幊搪劊夯A(chǔ)篇
- 微信小程序項(xiàng)目開發(fā)實(shí)戰(zhàn)
- Python算法詳解
- OpenCV 4計(jì)算機(jī)視覺項(xiàng)目實(shí)戰(zhàn)(原書第2版)
- Hands-On Nuxt.js Web Development
- CRYENGINE Game Development Blueprints
- Oracle 12c從入門到精通(視頻教學(xué)超值版)
- Visual C++從入門到精通(第2版)
- Learning D
- Microsoft HoloLens By Example
- Java程序設(shè)計(jì)教程
- Visual C++程序設(shè)計(jì)全程指南
- Hands-On ROS for Robotics Programming