user5746421
user5746421

Reputation:

Define `package private` access modifier in Java class

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

    package private Name;

How do I need to do this? thank you!

Upvotes: 4

Views: 32079

Answers (2)

Kayaman
Kayaman

Reputation: 73528

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

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

Upvotes: 28

gannicus
gannicus

Reputation: 51

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 docs you 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.

You can take reference from java docs.

Upvotes: 4

Related Questions