如何保护类,以使它们在其包之外不可见 [英] How to protect classes so they are not visible outside their package
本文介绍了如何保护类,以使它们在其包之外不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在我的包中有两个受保护的类。也就是说,我不希望我的包外面的文件看到它们是可见的 - 它们将只在包内部使用。
I'd like to be able to have two "protected" classes in my package. That is, I do not want files outside of my package to see them as visible - they will be for internal use within the package only.
我该如何做?
推荐答案
只要省略所有关键字即可。默认浏览权限是打包私有,可在
Just leave out all keywords. The default visibility is package-private, viewable within the package only.
例如:
// class Foo is public
public class Foo
{
final private Bar bar = ...;
}
// class Bar is package-private
// (visible to all classes in the package, not visible outside the package)
class Bar
{
...;
}
这篇关于如何保护类,以使它们在其包之外不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文