java 定义包私有java类

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34605696/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 23:06:19  来源:igfitidea点击:

Define package private java class

java

提问by BAM

I want to Define package private in Java but the compiler don't agree like this:

我想在 Java 中定义私有包,但编译器不同意这样的:

package private Name;

How I need to do this? thank you!

我需要怎么做?谢谢!

回答by Kayaman

"Package private" or "default" visibility modifier in Java is achieved by leaving out the visibility modifier (not the type). i.e.

Java 中的“包私有”或“默认”可见性修饰符是通过省略可见性修饰符(而不是类型)来实现的。IE

String name;            // package private or default
public String name;
private String name;
protected String name;

回答by gannicus

There is no way you can define a package with an access level modifiers.Packages are named groups of related classes.

您无法定义具有访问级别修饰符的包。包是相关类的命名组。

You are confusing the the term package private. If you go over to the java docsyou will see that package private word is used to signify default or no modifier .It means that a class or any member without any modifier will be visible only within its own package.

您混淆了术语package private。如果您转到java 文档,您将看到包私有字用于表示默认或无修饰符。这意味着没有任何修饰符的类或任何成员将仅在其自己的包中可见。

You can take reference from java docs.

您可以参考 java docs