访问说明符和访问修饰符的区别 [英] Difference between access specifier and access modifier

查看:37
本文介绍了访问说明符和访问修饰符的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在互联网上读过,我听到人们说

I've read around on the internet and I've heard people say

访问说明符::

访问说明符决定如何可访问的字段是编码其他班级.访问范围从完全可以访问到无法访问.您可以选择声明一个具有访问权限的字段说明符关键字:public、private、或受保护.

The access specifier determines how accessible the field is to code in other classes. Access ranges from totally accessible to totally inaccessible. You can optionally declare a field with an access specifier keyword: public, private, or protected.

访问修饰符::

您可以选择声明一个字段使用修饰符关键字:final 或易失性和/或静态和/或瞬态、抽象等

You can optionally declare a field with a modifier keyword: final or volatile and/or static and/or transient, abstract, etc.

有什么区别吗?因为大多数访问修饰符和访问说明符的定义都声明相同的事情......这看起来很模糊.

Is there any difference at all? Because most definitions for access modifiers and access specifiers state the same thing.. which seems so ambiguous.

推荐答案

在这种情况下,您可以将访问说明符视为保护说明符——它们指定变量可以访问.相比之下,访问修饰符则完全不同;它们指定如何变量应该(或不应该)被访问;例如只读、易失等

In this context, you can think of access specifiers as protection specifiers -- they specify where a variable can be accessed from. By contrast, access modifiers are completely different; they specify how variables should (or should not) be accessed; e.g. read-only, volatile, etc.

即,变量可以是公共的但只读的,也可以是私有的和可写的——访问说明符与修饰符无关.

i.e., a variable can be public but read-only, or it can be private and writable -- the access specifiers have nothing to do with the modifiers.

然而,我有点惊讶这个术语是针对 C# 的,因为微软实际上调用了 publicprivate "访问修饰符",它调用 volatilereadonly 只是简单的修饰符".

However, I'm a little surprised that the terminology is for C#, since Microsoft actually calls public and private "access modifiers", and it calls volatile and readonly just plain "modifiers".

这篇关于访问说明符和访问修饰符的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆