Java Access Levels(访问控制)
Access Levels
| Modifier | Class | Package | Subclass | World |
|---|---|---|---|---|
| public | Y | Y | Y | Y |
| protected | Y | Y | Y | N |
| no modifier | Y | Y | N | N |
| private | Y | N | N | N |
The following table shows where the members of the Alpha class are visible for each of the access modifiers that can be applied to them.
https://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html

| Modifier | Alpha | Beta | Alphasub | Gamma |
|---|---|---|---|---|
| public | Y | Y | Y | Y |
| protected | Y | Y | Y | N |
| no modifier | Y | Y | N | N |
| private | Y | N | N | N |
原来我一直都弄反了
protected的可见性实际上是大于package的.实习面试的时候,我一直都说错了。
Access Levels的实质
If you have a field that’s private it means no other class can get at it. Wrong! If you really want to you can subvert the access control mechanisms in almost any language. Usually the way through is via reflection. The rationale is that debuggers and other system tools often need to see private data , so usually the reflection interfaces allow you to do this.
C++ doesn’t have this kind of reflection, but there you can just use direct memory manipulation since C++ is fundamentally open memory.
The point of access control is not to prevent access, but more to signal that the class prefers to keep some things to itself. Using access modifiers, like so many things in programming, is primarily about communication.
http://martinfowler.com/bliki/AccessModifier.html
果然是专家,说出来的话太有水平了!
我理解的,访问控制实际是编译时有效的,类似于宏定义一样的东西,并不具备运行时检查。
不知道这个理解是不是错误的。我暂时还没找到去哪里验证这个观点。希望有人能给出切实的说法。
Java Access Levels(访问控制)的更多相关文章
- Illustrate Java Access Levels
https://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html 官网教程,清晰明了. (完)
- 详解Java中的访问控制修饰符(public, protected, default, private)
Java中的访问控制修饰符已经困惑笔者多时,其中较复杂的情况一直不能理解透彻.今天下定决心,系统.全面地研究Java中的访问控制修饰符的所有方面,并整理成这篇文章,希望有同样疑惑的读者读完后能有所收获 ...
- Java access to the Domino Objects, Part 1
From: https://www.ibm.com/developerworks/lotus/library/ls-Java_access_pt1/index.html Overview Java a ...
- Java学习笔记十九:Java中的访问控制修饰符
Java中的访问控制修饰符 一:Java修饰符的种类: 访问修饰符 非访问修饰符 修饰符用来定义类.方法或者变量,通常放在语句的最前端.我们通过下面的例子来说明: public class Hello ...
- Java之成员访问控制
Java中数据成员.方法成员有四种访问控制.
- Java 继承和访问控制
类的继承 Java中使用extends来实现继承 通过继承,子类自动拥有了基类(supercalss)的所有成员. Java只支持单继承,一个子类只允许有一个基类,一个基类可以有多个子类. class ...
- Java类成员访问控制权限
类成员访问控制权限 在JAVA中有四种访问控制权限,分别为:private, default, protected, public 1.Private 如果一个成员方法或变量名前使用了private, ...
- JAVA基础之访问控制权限
包:库单元 1.当编写一个Java源代码文件时,此文件通常被称为编译单元(有时也被称为转译单元). 2.每个编译单元都必须有一个后缀名.java,而在编译单元内则可以有一个public类,该类名称必须 ...
- java中的访问控制有什么用?如何用法?请举例
9.访问控制 [新手可忽略不影响继续学习] 访问控制有什么用?在软件公司里是这么用的,我们想像一种场景,在你的类中,你编了三个私有方法,马克-to-win,别人当然都用不了,但在类外,你也是用不了的, ...
随机推荐
- apue
#ifndef apue_h #define apue_h #define _POSIX_C_SOURCE 200809L #if defined(SOLARIS) /* Solaris 10 */ ...
- Filebeat中文指南
Filebeat中文指南 翻译自:https://www.elastic.co/guide/en/beats/filebeat/current/index.html 译者:kerwin 鸣谢:tory ...
- AngularJs学习笔记7——四大特性之模块化设计
模块化设计 1.引用自定义模块并调用 自定义模块中,如果有一些服务.封装好笑模块,在另外一个模块中(声明的时候,在依赖列表中加入要引入的模块) var app02 = angular.module(' ...
- 左右TextView旋转门问题
最近由于旋转门问题的一个客户找我,当在字符25更多的时候是不是走了,后来,我在重现的问题,发现问题如下面: 问题1.人物25几个月之内可以去. 问题2.在人物25个月,虽然比屏幕宽度,不去 问题3.屏 ...
- 【GitHub-SwipeMenuListView】针对ListView item的側滑菜单
项目地址:https://github.com/baoyongzhang/SwipeMenuListView Usage Step 1:import swipemenulistview.jar Ste ...
- 解决Android单个dex文件不能超过65536个方法问题
当我们的项目代码过大时,编译运行时会报Unable to execute dex: method ID not in[0, 0xffff]: 65536)错误.当出现这个错误时说明你本身自己的工程代码 ...
- Char Tools,方便的字符编码转换小工具
工作关系,常有字符编码转换方面的需要,写了这个小工具 Char Tools是一款方便的字符编码转换小工具,基于.Net Framework 2.0 Winform开发 主要功能 URL编码:URLEn ...
- Image控件的简单使用示例1
Image控件加载图片包括加载动态图片,加载静态图片两种方式.一.加载动态图片通过生成一个BitmapImage,创建该对象后,赋给Image的Source即可.加载的形式: 示例1 BitmapIm ...
- FeatureClass对象
概述: 在讲述FeatureClass对象之前,首先说明与FeatureClass对象相关的对象: Table对象,是不具有空间信息的二维表,是一张仅能在ArcMap的Table Of Content ...
- sqlite--代码操作
1.创建数据库 NSString * docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainM ...