How to protect classes so they are not visible outside their package

前端 未结 1 1230
悲&欢浪女
悲&欢浪女 2020-12-29 01:57

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 u

相关标签:
1条回答
  • 2020-12-29 02:18

    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 讨论(0)
提交回复
热议问题