{$cfg_webname}
主页 > 外文翻译 > 计算机翻译 >

Java访问权限修饰词

来源:wenku7.com  资料编号:WK712122 资料等级:★★★★★ %E8%B5%84%E6%96%99%E7%BC%96%E5%8F%B7%EF%BC%9AWK712122
以下是资料介绍,如需要完整的请充值下载。
1.无需注册登录,支付后按照提示操作即可获取该资料.
2.资料以网页介绍的为准,下载后不会有水印.资料仅供学习参考之用. 帮助
资料介绍

Java访问权限修饰词(中文5100字,英文3700字)
public、protected和private这几个Java访问权限修饰词在使用时,置于类中每个成员的 定义之前的-无论它是一个域还是一个方法。每个访问权限修饰词仅控制它所修饰的特定定义的 访问权。
如果不提供任何访问权限修饰词,则意味着它是“包访问权限”。因此,无论如何,所有事 物都具有某种形式的访问权限控制。在以下几节中,读者将学习各种类型的访问权限。
包访问权限
包访问权限允许将包内所有相关的类组合起来,以使它们彼此之间可以轻松地相互作用。 当把类组织起来放进一个包内之时,也就给它们的包访问权限的成员赋予了相互访问的权限, 你“拥有” 了该包内的程序代码。“只有你拥有的程序代码才可以访问你所拥有的其他程序代码”, 这是合理的。应该说,包访问权限为把类群聚在一个包中的做法提供了窓义和理由。在许多语 言中,在文件内组织定义的方式是任意的,但在Java中,则要强制你以一种合理的方式对它们 加以组织。另外,你可能还想要排除这样的类-它们不应该访问在当前包中所定义的类。

Java access specifiers
The Java access specifiers public, protected, and private are placed in front of each definition for each member in your class, whether it’s a field or a method. Each access specifier only controls the access for that particular definition.
If you don’t provide an access specifier, it means “package access.” So one way or another, everything has some kind of access control. In the following sections, you’ll learn about the various types of access.
Package access
Package access allows you to group related classes together in a package so that they can easily interact with each other. When you put classes together in a package, thus granting mutual access to their package-access members, you “own” the code in that package. It makes sense that only code that you own should have package access to other code that you own. You could say that package access gives a meaning or a reason for grouping classes together in a package. In many languages the way you organize your definitions in files can be arbitrary, but in Java you’re compelled to organize them in a sensible fashion. In addition, you’ll probably want to exclude classes that shouldn’t have access to the classes being defined in the current package.
 

推荐资料