开发者

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 开发者_如何学Cis, I do not want files outside of my package to see them as visible - they will be for internal use within the package only.

How can I do this?


Just leave out all keywords. The default visibility is package-private, viewable within the package only.

e.g.:

// 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
{
    ...;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜